Skip to content

Instantly share code, notes, and snippets.

@KartikTalwar
Last active December 30, 2015 05:29
Show Gist options
  • Save KartikTalwar/7783182 to your computer and use it in GitHub Desktop.
Save KartikTalwar/7783182 to your computer and use it in GitHub Desktop.
Make github repos sticky
import git
import json
import time
import urllib2
import datetime
def is_first(org, repo):
url = "https://api.github.com/users/%s/repos" % org
get = urllib2.urlopen(url).read()
data = []
for repo in json.loads(get):
timestamp = time.strftime("%s", time.strptime(repo['pushed_at'], "%Y-%m-%dT%H:%M:%SZ"))
data.append({"name": repo['name'].lower(), "modified" : int(timestamp)})
newlist = sorted(data, key=lambda x: x['modified'])
return newlist[-1]['name'] == repo
if __name__ == '__main__':
if not is_first('coderdojosf', 'welcome'):
dname = '/home/ktalwar/git/welcome'
fname = dname + '/sticky.txt'
open(fname, 'a').write(' ')
repo = git.Repo(dname)
repo.git.add(fname)
repo.git.commit(m='sticky post')
master = repo.remotes.origin
master.push()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment