Skip to content

Instantly share code, notes, and snippets.

@rsp9u
Created August 19, 2021 18:32
Show Gist options
  • Select an option

  • Save rsp9u/758bbe69d5f37685c14a921a6dd7cf4c to your computer and use it in GitHub Desktop.

Select an option

Save rsp9u/758bbe69d5f37685c14a921a6dd7cf4c to your computer and use it in GitHub Desktop.
import feedparser
from datetime import datetime
dt_fmt = "%a, %d %b %Y %H:%M:%S %Z"
def rss2mm(feed_url, until, max_n=3):
ret_lines = []
f = feedparser.parse(feed_url)
for idx, e in enumerate(f["entries"]):
dt = datetime.strptime(e["published"], dt_fmt)
if dt < until or idx >= max_n:
break
ret_lines.append("##### [{}]({})".format(e["title"], e["link"]))
ret_lines.append("```")
ret_lines += list(filter(lambda x: x != "", e["summary"].split("\n")))[:3]
ret_lines.append("```")
ret_lines.append("")
return "\n".join(ret_lines)
if __name__ == "__main__":
until = datetime(2021, 8, 10)
print("# POSTD")
print(rss2mm("https://postd.cc/feed", until))
print("# Zenn")
print(rss2mm("https://zenn.dev/feed", until))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment