Create a gist now

Instantly share code, notes, and snippets.

Subreddit flair stats
#!/usr/bin/env python
import sys
from datetime import datetime
from praw import Reddit
user = 'rasherdk'
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:
if ' official' in style:
style = style.replace(' official', '')
if style not in teams:
sys.stderr.write("Ignore %s\n" % style)
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"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment