forked from SergSlipushenko/review-stats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
review-stats.py
executable file
·45 lines (38 loc) · 1.29 KB
/
review-stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import requests
import time
import datetime
ACTIVITY_URL = 'http://stackalytics.com/api/1.0/activity?' \
'user_id=%s&module=fuel-group&page_size=100500&start_record=0'
REVIEW_URL = 'https://review.openstack.org/%s'
def main(args):
print 'Fetching stats...'
req = requests.get(ACTIVITY_URL % args.user)
print 'Done.'
activities = req.json()['activity']
unique_reviews = {}
past = datetime.date.today() - datetime.timedelta(days=5)
unique = set()
for a in activities:
if a['parent_url'] in unique:
continue
unique.add(a['parent_url'])
adate = datetime.date.fromtimestamp(a['date'])
if adate > past:
unique_reviews.setdefault(adate, []).append(a['parent_url'])
keys = sorted(unique_reviews.keys())
for k in keys:
print k
for e in unique_reviews[k]:
print e
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Review story point counter tool',
formatter_class=argparse.RawDescriptionHelpFormatter,
usage='./review-stats.py [-h] GERRIT-USER-ID'
)
parser.add_argument('user', type=str,
help='Gerrit user id')
exit(main(parser.parse_args()))