Skip to content

Instantly share code, notes, and snippets.

@brighteyed
Created September 26, 2019 09:32
Show Gist options
  • Save brighteyed/c32703d767764730d56f6b46839f21ee to your computer and use it in GitHub Desktop.
Save brighteyed/c32703d767764730d56f6b46839f21ee to your computer and use it in GitHub Desktop.
Save list of starred repositories to JSON file. Copied from https://jpmens.net/2019/04/04/i-clone-all-repositories-i-ve-starred/
#!/usr/bin/env python
from github import Github # https://github.com/PyGithub/PyGithub
import json
import os
g = Github(open(os.path.expanduser("~/.gist")).read())
starred = []
for repo in g.get_user().get_starred():
# I find stars some of my own repositories, and I don't think
# I actually did that; artefact of prior GitHub practices?
if repo.owner.login != "jpmens":
data = {
"name" : repo.name,
"owner" : repo.owner.login,
"full_name" : repo.full_name,
"clone_url" : repo.clone_url,
}
if repo.owner.name:
data["owner_name"] = repo.owner.name
if repo.owner.email:
data["owner_email"] = repo.owner.email
if repo.owner.avatar_url:
data["owner_avatar_url"] = repo.owner.avatar_url
if repo.description:
data["description"] = repo.description
if repo.homepage:
data["homepage"] = repo.homepage
topics = repo.get_topics() # removing this speeds up the program
if len(topics) != 0:
data["topics"] = topics
starred.append(data)
with open("starred.json", "w") as f:
f.write(json.dumps(starred, indent=4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment