Skip to content

Instantly share code, notes, and snippets.

@fordhurley
Forked from wsorenson/hipchat.py
Last active April 6, 2024 14:40
Show Gist options
  • Save fordhurley/9505628 to your computer and use it in GitHub Desktop.
Save fordhurley/9505628 to your computer and use it in GitHub Desktop.
Updated script to log in with email and password and minor updates to the scraper
#!/usr/bin/env python
# encoding: utf-8
import sys
import os
import re
import getpass
import requests
# Set this to the company domain (as in DOMAIN.hipchat.com):
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:([^<]+)<')
s = requests.Session()
r = s.get('https://www.hipchat.com/sign_in')
data = {}
data['email'] = raw_input('Email: ')
data['password'] = getpass.getpass()
print "Logging in..."
r = s.post('https://www.hipchat.com/sign_in', data=data)
r.raise_for_status()
print "fetching member list..."
r = s.get(url)
all_stats = []
for member in regexp.findall(r.content):
member_url = template % member
print "fetching", member
r = s.get(member_url)
stats = sent_regexp.findall(r.content)[0]
signed_up = signed_up_regexp.findall(r.content)[0].strip().lower()
stats = stats.strip().replace(',', '')
member = member.split('/')[2]
name_split = member.split('-')
name = " ".join([n.strip().capitalize() for n in name_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