Last active
April 19, 2017 10:17
-
-
Save pshchelo/dfaec00143054e2cfc2cbcd50b9f67e0 to your computer and use it in GitHub Desktop.
Stackalytics stats fetcher
This file contains hidden or 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
#!/usr/bin/env python | |
import calendar | |
import datetime | |
import time | |
import requests | |
from six.moves.urllib import parse as urlparse | |
TEAM = [ | |
'vdrok', | |
'yzveryanskyy', | |
'aarefiev', | |
'kromanenko', | |
'ipukha', | |
'sturivnyi', | |
'gzholtkevych', | |
'sandriichenko', | |
'vhmyrov', | |
'serge-kovaleff', | |
'ashestakov', | |
'pshchelo', | |
'vsaienko', | |
'ovoshchana', | |
] | |
START = datetime.datetime(2016, 7, 1).utctimetuple() | |
END = datetime.datetime(2016, 9, 30).utctimetuple() | |
stackalytics = "http://stackalytics.com/api/1.0/" | |
adapter = requests.adapters.HTTPAdapter() | |
session = requests.Session() | |
session.mount(stackalytics, adapter) | |
stats = [] | |
for name in TEAM: | |
params = { | |
'release': 'all', | |
'user_id': name, | |
'start_date': calendar.timegm(START), | |
'end_date': calendar.timegm(END), | |
} | |
url = urlparse.urljoin(stackalytics, 'contribution') | |
resp = session.get(url, params=params) | |
if resp.status_code != requests.codes.OK: | |
print("Failed to fetch stats for user {}".format(name)) | |
continue | |
data = resp.json()['contribution'] | |
data['user_id'] = name | |
data['reviews'] = sum(data['marks'][mark] | |
for mark in map(str, range(-2, 3))) | |
stats.append(data) | |
totals = {} | |
for field, value in stats[0].items(): | |
if isinstance(value, int): | |
totals[field] = sum(item[field] for item in stats) | |
print("start: {}".format(time.strftime("%x", START))) | |
print("end: {}".format(time.strftime("%x", END))) | |
for key, val in totals.items(): | |
print("{field} = {total}".format(field=key, total=val)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment