Skip to content

Instantly share code, notes, and snippets.

@tur1ngb0x
Created February 16, 2023 05:38
Show Gist options
  • Save tur1ngb0x/41c408847ab3fbb8a3ed609a05cf45b8 to your computer and use it in GitHub Desktop.
Save tur1ngb0x/41c408847ab3fbb8a3ed609a05cf45b8 to your computer and use it in GitHub Desktop.
get-gists.py
#!/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)
$ get-gists.py username
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment