diff --git a/.gitignore b/.gitignore index 3b99e4d..1fbadaf 100644 --- a/.gitignore +++ b/.gitignore @@ -127,4 +127,5 @@ dmypy.json # Pyre type checker .pyre/ -/.idea/ \ No newline at end of file +/.idea/ +/test/*.json \ No newline at end of file diff --git a/test/example.json b/test/example.json deleted file mode 100644 index 0637a08..0000000 --- a/test/example.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/test/rss.py b/test/rss.py index 57dc382..09393e8 100644 --- a/test/rss.py +++ b/test/rss.py @@ -1,8 +1,24 @@ import feedparser import json +import sys +import os -url = "https://rsshub.app/bilibili/user/bangumi/2975898" -d = feedparser.parse(url)["entries"] -with open("example.json", "w") as t: - json.dump(d, t, indent=4, ensure_ascii=False) +my_path = __file__ +my_direc = os.path.dirname(__file__) + +def parseUrl(url: str="https://github.com/Apocalypsor/Formatted-RSS-to-Telegram/commits/main.atom"): + d = feedparser.parse(url)["entries"] + + file_name = url.replace("https://", "").replace("http://", "").replace("/", "_") + with open(os.path.join(my_direc, f"{file_name}.json"), "w", encoding="UTF-8") as t: + json.dump(d, t, indent=4, ensure_ascii=False) + +if __name__ == "__main__": + if len(sys.argv) == 1: + parseUrl() + elif len(sys.argv) == 2: + parseUrl(sys.argv[1]) + else: + for u in sys.argv[1:]: + parseUrl(u)