-
-
Save selimslab/958e2255a105f9a3f4b421896bce715d to your computer and use it in GitHub Desktop.
Download all gists of a user
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 | |
from subprocess import call | |
import json | |
import os | |
import requests | |
def download_gists(gists: list): | |
for gist in gists: | |
call(["git", "clone", gist["git_pull_url"]]) | |
# name of the first file in the gist | |
new_folder_name = sorted(list(gist.get("files", {}).keys()))[0].split(".")[0] | |
os.rename(gist["id"], new_folder_name) | |
description_file = os.path.join(new_folder_name, "description.txt") | |
with open(description_file, "w") as f: | |
f.write(f"{gist['description']}\n") | |
def visit_pages(user: str): | |
next_page = True | |
page = 1 | |
while next_page: | |
url = f"https://api.github.com/users/{user}/gists?page={page}" | |
r = requests.get(url) | |
if not len(r.json()): | |
next_page = False | |
else: | |
page += 1 | |
download_gists(r.json()) | |
user = sys.argv[1] | |
visit_pages(user) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is amazing :) thank you