From f73755fb5c90de02f3f75541be8e02acd6ab579d Mon Sep 17 00:00:00 2001 From: lifeadventurer Date: Sat, 12 Oct 2024 01:44:16 +0800 Subject: [PATCH] add scripts/readme_crawler.py --- .gitignore | 2 ++ scripts/readme_crawler.py | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 scripts/readme_crawler.py diff --git a/.gitignore b/.gitignore index 7ad2044..c08df47 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ dev/ site/ .vscode/ + +temp_readme.md diff --git a/scripts/readme_crawler.py b/scripts/readme_crawler.py new file mode 100644 index 0000000..ecec10e --- /dev/null +++ b/scripts/readme_crawler.py @@ -0,0 +1,27 @@ +import requests + + +def get_readme(username, repository): + url = f"https://raw.githubusercontent.com/{username}/{repository}/master/README.md" + response = requests.get(url) + if response.status_code == 200: + return response.text + else: + return None + + +def main(): + username = input("Enter GitHub username: ") + repository = input("Enter repository name: ") + readme_content = get_readme(username, repository) + if readme_content: + print("README successfully fetched.") + with open("./temp_readme.md", "w", encoding="utf-8") as f: + f.write(readme_content) + print("README saved successfully.") + else: + print("Failed to fetch README.") + + +if __name__ == "__main__": + main()