Show More
@@ -0,0 +1,31 b'' | |||||
|
1 | import json | |||
|
2 | from datetime import datetime, timedelta | |||
|
3 | import sys | |||
|
4 | from urllib import urlopen | |||
|
5 | ||||
|
6 | def get_issues(project="ipython/ipython/", state="open"): | |||
|
7 | """Get a list of the issues from the Github API.""" | |||
|
8 | f = urlopen("http://github.com/api/v2/json/issues/list/%s%s" % (project, state)) | |||
|
9 | return json.load(f)['issues'] | |||
|
10 | ||||
|
11 | def _parse_datetime(s): | |||
|
12 | """Parse dates in the format returned by the Github API.""" | |||
|
13 | return datetime.strptime(s.rpartition(" ")[0], "%Y/%m/%d %H:%M:%S") | |||
|
14 | ||||
|
15 | def issues_closed_since(period=timedelta(days=365), project="ipython/ipython/"): | |||
|
16 | """Get all issues closed since a particular point in time. period | |||
|
17 | can either be a datetime object, or a timedelta object. In the | |||
|
18 | latter case, it is used as a time before the present.""" | |||
|
19 | allclosed = get_issues(project=project, state='closed') | |||
|
20 | if isinstance(period, timedelta): | |||
|
21 | period = datetime.now() - period | |||
|
22 | return [i for i in allclosed if _parse_datetime(i['closed_at']) > period] | |||
|
23 | ||||
|
24 | if __name__ == "__main__": | |||
|
25 | # Demo | |||
|
26 | if len(sys.argv) > 1: | |||
|
27 | days = int(sys.argv[1]) | |||
|
28 | else: | |||
|
29 | days = 365 | |||
|
30 | n = len(issues_closed_since(timedelta(days=days))) | |||
|
31 | print "%d issues closed in the last %d days." % (n, days) |
General Comments 0
You need to be logged in to leave comments.
Login now