Created
September 16, 2012 18:00
-
-
Save hktechn0/3733499 to your computer and use it in GitHub Desktop.
PyCon JP 2012 Get RedBull Challenge
This file contains hidden or 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
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