-
-
Save mchail/8033662 to your computer and use it in GitHub Desktop.
Calculate hipchat comments/day. Forked from @wsorenson.
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
#!/usr/bin/env python | |
# encoding: utf-8 | |
import sys | |
import os | |
import requests | |
import re | |
# log in on the browser and supply the full cookie sent to HipChat as well as the company domain. | |
COOKIE = '' | |
DOMAIN = '' | |
def main(): | |
url = 'https://%s.hipchat.com/people' % DOMAIN | |
template = url + "/%s" | |
regexp = re.compile(r'people/([^"]+)"') | |
sent_regexp = re.compile(r'Messages sent:([^<]+)<') | |
signed_up_regexp = re.compile(r'Signed up:([^<]+)<') | |
headers = {'Cookie': COOKIE } | |
print "fetching member list..." | |
body = requests.get(url, headers=headers) | |
all_stats = [] | |
for member in regexp.findall(body.content): | |
member_url = template % member | |
print "fetching", member_url | |
body2 = requests.get(member_url, headers=headers) | |
stats = sent_regexp.findall(body2.content)[0] | |
signed_up = signed_up_regexp.findall(body2.content)[0].strip().lower() | |
stats = stats.strip().replace(',', '') | |
name = member.split('/')[-1] | |
member = member.split('/')[1] | |
name_split = member.split('-') | |
signed_up = signed_up.strip().split(' ') | |
if signed_up[0] == 'today' or signed_up[0] == 'yesterday': | |
days = 1 | |
else: | |
number = int(signed_up[0]) | |
date_type = signed_up[1] | |
if date_type == 'year' or date_type == 'years': | |
days = number * 365 | |
elif date_type == 'months' or date_type == 'month': | |
days = number * 30 | |
elif date_type == 'weeks' or date_type == 'week': | |
days = number * 7 | |
elif date_type == 'days' or date_type == 'day': | |
days = number | |
else: | |
days = 0 | |
print "unknown date_type: %s" % date_type | |
stats = int(stats) | |
rate = 0 | |
if days > 0: | |
rate = (float(stats) / days) | |
stats_triple = (stats, name, rate) | |
all_stats.append(stats_triple) | |
counter = 1 | |
for score, name, rate in sorted(all_stats, reverse=True): | |
print "%s. %s - %s (%.02f/day)" % (counter, name, score, rate) | |
counter += 1 | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment