Created
July 23, 2011 21:14
-
-
Save takluyver/1101890 to your computer and use it in GitHub Desktop.
Get issues from JSON API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from urllib import urlopen | |
def get_issues(project="ipython/ipython/", state="open"): | |
f = urlopen("http://github.com/api/v2/json/issues/list/%s%s" % (project, state)) | |
return json.load(f)['issues'] | |
def _parse_datetime(s): | |
"""Parse dates in the format returned by the Github API""" | |
return datetime.strptime(s.rpartition(")[0], ") | |
def issues_closed_since(period=timedelta(days=365), project="ipython/ipython/"): | |
"""Get all issues closed since a particular point in time. period | |
can either be a datetime object, or a timedelta object. In the | |
latter case, it is used as a time before the present.""" | |
allclosed = get_issues(project=project, state='closed') | |
if isinstance(period, timedelta): | |
period = datetime.now() - period | |
return [i for i in allclosed if _parse_datetime(i['closed_at']) > period] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment