Skip to content

Instantly share code, notes, and snippets.

@bennuttall
Last active September 9, 2019 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennuttall/20c67f4dc6b7bd4d7a7ed4352505b8bb to your computer and use it in GitHub Desktop.
Save bennuttall/20c67f4dc6b7bd4d7a7ed4352505b8bb to your computer and use it in GitHub Desktop.
from github import Github
from time import sleep
token = '' # enter your github access token
def is_language(path):
# a function to determine whether or not a path from a git tree is a language folder
# must be a "tree" (a folder) rather than a file
# must be 5 characters long with a hyphen in the middle e.g. "fr-CA"
return item.type == 'tree' and len(path) == 5 and path[2] == '-'
# start with an empty dictionary of projects
# this will be filled with project names mapped to a set of languages
# e.g. 'storytime': {'fr-CA', 'fr-'}
projects = {}
github = Github(token)
# get all repos from the org "raspberrypilearning"
org = github.get_organization('raspberrypilearning')
repos = org.get_repos()
while True:
for repo in repos:
# if unknown project, add it to the dictionary
if repo.name not in projects:
print(f'new project: {repo.name}')
projects[repo.name] = set()
known_langs = projects[repo.name] # look up known languages from last check
last_commit = repo.get_commits()[0] # get latest commit hash
tree = repo.get_git_tree(last_commit.sha) # get git tree of latest commit
langs = set() # create an empty set of languages
# look for language folders in the git tree, and add them to the languages set
for item in tree.tree:
if is_language(item.path):
langs.add(item.path)
new_langs = langs.difference(known_langs) # compare previously known languages with now to see if there are any new ones
projects[repo.name] = langs # update known languages in the dictionary
if new_langs:
print('new language!')
for lang in new_langs:
print(f'{repo.name} - new language: {lang}')
sleep(60*60) # check every hour
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment