Created
April 2, 2023 08:30
-
-
Save harukaeru/40fddf5d66af5f3bba35f760f677f9ad to your computer and use it in GitHub Desktop.
GitHubのファイルをダウンロードする
This file contains 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 sys | |
import requests | |
def convert_github_url_to_raw(url): | |
raw_url = url.replace("github.com", "raw.githubusercontent.com") | |
raw_url = raw_url.replace("/blob", "") | |
return raw_url | |
def download_and_save(url, filename): | |
raw_url = convert_github_url_to_raw(url) | |
response = requests.get(raw_url) | |
if response.status_code == 200: | |
with open(filename, "wb") as f: | |
f.write(response.content) | |
else: | |
print("Error while downloading file. Status code: ", response.status_code) | |
if __name__ == "__main__": | |
if len(sys.argv) != 3: | |
print("Usage: python3 generate.py <output_filename> <github_url>") | |
else: | |
output_filename = sys.argv[1] | |
github_url = sys.argv[2] | |
download_and_save(github_url, output_filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment