Skip to content

Instantly share code, notes, and snippets.

@Vostbur
Created March 13, 2022 08:12
Show Gist options
  • Save Vostbur/3c8da88bab79cc85d4a9fe61fb9421f1 to your computer and use it in GitHub Desktop.
Save Vostbur/3c8da88bab79cc85d4a9fe61fb9421f1 to your computer and use it in GitHub Desktop.
Backup (clone) all your own gists
#!/usr/bin/env python -B
# pip install PyGithub
from github import Github
import pathlib
import json
import os
gists = []
g = Github(open(pathlib.Path.home() / ".github_access_token").read())
for gist in g.get_user().get_gists():
gists.append({
"id": gist.id,
"description": gist.description,
"public": gist.public,
"clone": gist.git_pull_url,
"updated": gist.updated_at.isoformat(),
"url": gist.url,
})
os.system("git clone {0} repos/{1}".format(gist.git_pull_url, gist.id))
with open("index.json", "w") as f:
f.write(json.dumps(gists, indent=4) + "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment