Skip to content

Instantly share code, notes, and snippets.

Last active September 9, 2019 13:59
What would you like to do?
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 not in projects:
print(f'new project: {}')
projects[] = set()
known_langs = projects[] # 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):
new_langs = langs.difference(known_langs) # compare previously known languages with now to see if there are any new ones
projects[] = langs # update known languages in the dictionary
if new_langs:
print('new language!')
for lang in new_langs:
print(f'{} - 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