Skip to content

Instantly share code, notes, and snippets.

@benregn
Created November 9, 2016 15:40
Show Gist options
  • Save benregn/21dee306f449b6a2ba3f0166b1d9f12f to your computer and use it in GitHub Desktop.
Save benregn/21dee306f449b6a2ba3f0166b1d9f12f to your computer and use it in GitHub Desktop.
import json
from collections import defaultdict
import requests
token = '<github-access-token>'
gh_url = 'https://api.github.com'
headers = {'Authorization': 'token {}'.format(token)}
resp = requests.get(gh_url + '/users/benregn/events', headers=headers)
happenings = defaultdict(lambda: defaultdict(list))
for each in resp.json():
if each['type'] != 'PushEvent':
continue
created_date, created_time = each['created_at'][:-1].split('T')
repo_name = each['repo']['name']
commits = [
{
'message': c['message'],
'time': created_time,
}
for c in each['payload']['commits']
]
happenings[created_date][repo_name].extend(commits)
print(json.dumps(happenings, indent=2, sort_keys=True))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment