Skip to content

Commit

Permalink
update to github api v3
Browse files Browse the repository at this point in the history
  • Loading branch information
mansr committed Aug 12, 2015
1 parent 008ba76 commit fec5764
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions g_octave/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
else:
import urllib2 as urllib

import codecs
import glob
import json
import os
Expand All @@ -54,7 +55,7 @@ class GitHub:
def __init__(self, user, repo):
self.user = user
self.repo = repo
self.api_url = 'http://github.com/api/v2/json'
self.api_url = 'https://api.github.com'
self.url = 'http://github.com'

def need_update(self):
Expand All @@ -63,23 +64,24 @@ def need_update(self):
))

def get_commits(self, branch='master'):
url = '%s/commits/list/%s/%s/%s/' % (
url = '%s/repos/%s/%s/commits/%s' % (
self.api_url,
self.user,
self.repo,
branch
)
commits = {}
with closing(urllib.urlopen(url)) as fp:
commits = json.load(fp)
return commits['commits']
reader = codecs.getreader('utf-8')
commits = json.load(reader(fp))
return commits

def fetch_db(self, branch='master'):
cache = os.path.join(conf.db, 'cache')
commit_id = os.path.join(cache, 'commit_id')
if not os.path.exists(cache):
os.makedirs(cache)
last_commit = self.get_commits()[0]['id']
last_commit = self.get_commits()['sha']
if os.path.exists(commit_id):
with open_(commit_id) as fp:
if fp.read().strip() == last_commit:
Expand Down

0 comments on commit fec5764

Please sign in to comment.