Created
August 19, 2021 18:32
-
-
Save rsp9u/758bbe69d5f37685c14a921a6dd7cf4c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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