public
Last active

Subreddit flair stats

  • Download Gist
flairstats.py
Python
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#!/usr/bin/env python
import sys
from datetime import datetime
from praw import Reddit
 
user = 'rasherdk'
password = 'PASSWORDGOESHERE'
srname = 'nfl'
 
r = Reddit('flairstats/0.1')
r.login(user, password)
sr = r.get_subreddit(srname)
 
teams = {
'afc': 'American Football Conference',
'bears': 'Chicago Bears',
'bengals': 'Cincinnati Bengals',
'bills': 'Buffalo Bills',
'broncos': 'Denver Broncos',
'browns': 'Cleveland Browns',
'buccaneers': 'Tampa Bay Buccaneers',
'cardinals': 'Arizona Cardinals',
'chargers': 'San Diego Chargers',
'chiefs': 'Kansas City Chiefs',
'colts': 'Indianapolis Colts',
'cowboys': 'Dallas Cowboys',
'dolphins': 'Miami Dolphins',
'eagles': 'Philadelphia Eagles',
'falcons': 'Atlanta Falcons',
'fortyniners': 'San Francisco 49ers',
'giants': 'New York Giants',
'jaguars': 'Jacksonville Jaguars',
'jets': 'New York Jets',
'lions': 'Detroit Lions',
'nfc': 'National Football Conference',
'nfl': 'National Football League',
'oilers': 'Houston Oilers',
'packers': 'Green Bay Packers',
'panthers': 'Carolina Panthers',
'patriots': 'New England Patriots',
'raiders': 'Oakland Raiders',
'rams': 'St. Louis Rams',
'ravens': 'Baltimore Ravens',
'redskins': 'Washington Redskins',
'saints': 'New Orleans Saints',
'seahawks': 'Seattle Seahawks',
'steelers': 'Pittsburgh Steelers',
'texans': 'Houston Texans',
'titans': 'Tennessee Titans',
'vikings': 'Minnesota Vikings'
}
 
stats = {}
total = 0
for item in sr.flair_list():
style = item['flair_css_class']
if not style:
continue
if ' official' in style:
style = style.replace(' official', '')
if style not in teams:
sys.stderr.write("Ignore %s\n" % style)
continue
if style not in stats:
stats[style] = 0
stats[style] += 1
total += 1
items = stats.items()
items.sort(lambda x,y: cmp(y[1], x[1]))
for style, count in items:
print(" %5d (%5.1f%%) %s" % (count, float(count*100.0)/total, teams[style]))
print(" %5d (100.0%%) %s" % (total, "Total"))
print("*Updated %s*" % datetime.utcnow().strftime("%Y-%m-%d %H:%MZ"))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.