Skip to content

Instantly share code, notes, and snippets.

@andreas-mausch
Last active August 18, 2018 21:55
Show Gist options
  • Save andreas-mausch/da209a20f71f55e339a9d739e07d23d1 to your computer and use it in GitHub Desktop.
Save andreas-mausch/da209a20f71f55e339a9d739e07d23d1 to your computer and use it in GitHub Desktop.
Download all starred GitHub repos
#!/usr/bin/env python
import datetime
import logging
import requests
from plumbum import cli
from plumbum import local
from requests.auth import HTTPBasicAuth
logging.basicConfig(format="%(asctime)s %(message)s", datefmt="%Y-%m-%d %H:%M:%S")
logger = logging.getLogger(__name__)
class GithubDowloader(cli.Application):
def main(self, *srcfiles):
logger.setLevel(logging.INFO)
starredRepos = self.starredRepos()
for i, starredRepo in enumerate(starredRepos):
logger.info("Bundling {}/{}: {}".format(i+1, len(starredRepos), starredRepo["name"]))
self.download(starredRepo["full_name"].replace("/","-"), starredRepo["clone_url"])
def starredRepos(self):
username = "andreas-mausch"
password = "123456"
logger.info("Finding all starred repos for {}".format(username))
page = 0
starredRepos = []
while True:
page = page + 1
response = requests.get("https://api.github.com/users/andreas-mausch/starred?page={}".format(page), auth=HTTPBasicAuth(username, password)).json()
if not response:
break
starredRepos.extend(response)
logger.info("Found {} repos.".format(len(starredRepos)))
return starredRepos
def download(self, name, url):
try:
logger.info("Cloning: {} from {}".format(name, url))
today = datetime.date.today().strftime("%Y-%m-%d")
git = local["git"]
git("clone", url, "repo")
git("--git-dir", "./repo/.git", "bundle", "create", "{}-{}.bundle".format(today, name), "--all")
finally:
rm = local["rm"]
rm("-rf", "repo")
if __name__ == "__main__":
GithubDowloader.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment