Skip to content

Instantly share code, notes, and snippets.

@carlthome
Last active June 5, 2022 11:27
Show Gist options
  • Save carlthome/57ddf56eb35c851000f2a8dd792fb868 to your computer and use it in GitHub Desktop.
Save carlthome/57ddf56eb35c851000f2a8dd792fb868 to your computer and use it in GitHub Desktop.
Clone all gists for a given user.
"""Clone all gists repos for user."""
import argparse
import json
from multiprocessing.dummy import Pool
from pathlib import Path
from subprocess import call
from urllib.request import urlopen
def pull(gist):
assert gist["git_pull_url"] == gist["git_push_url"]
repo_url = gist["git_pull_url"]
assert gist["id"] in repo_url
repo_dir = Path(gist["id"])
if repo_dir.is_dir():
assert call(f"cd {repo_dir}; git pull", shell=True) == 0
else:
assert call(f"git clone {repo_url}", shell=True) == 0
parser = argparse.ArgumentParser(description="Clone all gist repos for provided user.")
parser.add_argument("--username", type=str, required=True, help="GitHub.com username")
args = parser.parse_args()
username = args.username
gists = json.load(urlopen(f"https://api.github.com/users/{username}/gists"))
with Pool() as pool:
pool.map(pull, gists)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment