Skip to content

Instantly share code, notes, and snippets.

@hktechn0
Created September 16, 2012 18:00
Show Gist options
  • Save hktechn0/3733499 to your computer and use it in GitHub Desktop.
Save hktechn0/3733499 to your computer and use it in GitHub Desktop.
PyCon JP 2012 Get RedBull Challenge
import sys
from HTMLParser import HTMLParser
value = dict()
class MyHTMLParser(HTMLParser):
isuser = False
def handle_starttag(self, tag, attrs):
if tag == "p" and dict(attrs).get("class", None) == "user":
self.isuser = True
def handle_data(self, data):
if data.strip() and self.isuser:
self.isuser = False
for c in data:
i = c.upper()
value[i] = value.get(i, 0) + 1
def handle_endtag(self, tag):
pass
parser = MyHTMLParser()
f = open(sys.argv[1])
txt = f.read()
parser.feed(txt)
parser.close()
f.close()
#print value
#print list(value)
a = value.items()
a.sort(cmp=lambda x,y: cmp(x[1], y[1]))
print a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment