Created
February 16, 2023 05:38
-
-
Save tur1ngb0x/41c408847ab3fbb8a3ed609a05cf45b8 to your computer and use it in GitHub Desktop.
get-gists.py
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
#!/usr/bin/env python3 | |
from concurrent.futures import ThreadPoolExecutor | |
from subprocess import call | |
import hashlib | |
import json | |
import os | |
import requests | |
import sys | |
def download_all_from_user(user: str): | |
next_page = True | |
page = 1 | |
while next_page: | |
url = f"https://api.github.com/users/{user}/gists?page={page}" | |
response = requests.get(url) | |
if not len(response.json()): | |
next_page = False | |
else: | |
page += 1 | |
download_all(response.json()) | |
def download_all(gists: list): | |
with ThreadPoolExecutor(max_workers=10) as executor: | |
for _ in executor.map(download, gists): | |
pass | |
def download(gist): | |
target = gist["id"] + hashlib.md5(gist["updated_at"].encode('utf-8')).hexdigest() | |
call(["git", "clone", gist["git_pull_url"], target]) | |
description_file = os.path.join(target, "description.txt") | |
with open(description_file, "w") as f: | |
f.write(f"{gist['description']}\n") | |
user = sys.argv[1] | |
download_all_from_user(user) |
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
$ get-gists.py username |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment