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
from github import Github, GithubException | |
import json | |
from datetime import datetime | |
import os | |
def main(token): | |
g = Github(token) | |
alphagov = g.get_organization('alphagov') | |
mirror = g.get_organization('alphagov-mirror') | |
count=0 | |
names = [] | |
for repo in alphagov.get_repos('all'): | |
names.append(repo.name) | |
try: | |
mirror.create_fork(repo) | |
except GithubException as e: | |
print("Skipping %s, got error: %s"%(repo.name, e)) | |
count += 1 | |
if count % 10 == 0: | |
print("%d done"%count) | |
print("imported %d repositories"%count) | |
out_file_name = "out-%s.json"%datetime.now() | |
print("Writing %s"%out_file_name) | |
with open(out_file_name, "w") as out_file: | |
json.dump(names, out_file) | |
if __name__ == '__main__': | |
main(os.getenv("GITHUB_TOKEN")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment