Skip to content

Instantly share code, notes, and snippets.

@Red5d
Last active February 2, 2016 18:02
Show Gist options
  • Save Red5d/8d9d8c71520320130a7e to your computer and use it in GitHub Desktop.
Save Red5d/8d9d8c71520320130a7e to your computer and use it in GitHub Desktop.
Python script to show the latest updates to an awesome-<whatever> list repo.
#! /usr/bin/env python
# Example: python ghfeed-updates.py vinta/awesome-python
import sys, re, requests
repo = sys.argv[1]
token="<personal GitHub token here>"
if token == "<personal GitHub token here>":
print "Add your personal GitHub token to the 'token=' line in the script."
sys.exit()
headers = {'Accept': 'application/vnd.github.v3.diff', 'Authorization': 'token '+token}
commits = requests.get("https://api.github.com/repos/"+repo+"/commits", headers=headers).json()
def getChanges(url):
r = requests.get(url, headers=headers)
additions = []
for line in r.text.split('\n'):
if re.match('^\+', line):
additions.append(line)
return additions
cnum = 0
for commit in commits:
if len(sys.argv) >= 3:
if cnum == int(sys.argv[2]):
exit()
if commit['author']['login'] == repo.split('/')[0] or commit['commit']['message'].split(' ')[0] == "Merge":
cnum = cnum + 1
lines = getChanges(commit['url'])
for line in lines:
print line.replace('+', '')
print "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment