classSummaryParser(htmllib.HTMLParser):# derive new HTML parser
defget_attr(self,attrs,key):
#print attrs;
forainattrs:
ifa[0]==key:
# print key,"=",a[1]
returna[1]
returnNone
def__init__(self,formatter):# class constructor
htmllib.HTMLParser.__init__(self,formatter)# base class constructor
self.nofill=True
self.SiteName=None
self.TourneyId=None
self.TourneyName=None
self.nextStartTime=False
self.TourneyStartTime=None
self.nextEndTime=False
self.TourneyEndTime=None
self.TourneyGameType=None
self.nextGameType=False
self.nextStructure=False
self.TourneyStructure=None
self.nextBuyIn=False
self.TourneyBuyIn=None
self.nextPool=False
self.TourneyPool=None
self.nextPlayers=False
self.TourneyPlayers=None
self.nextAllowRebuys=False
self.TourneyRebuys=None
self.parseResultsA=False
self.parseResultsB=False
self.TempResultStore=[0,0,0,0]
self.TempResultPos=0
self.Results={}
defstart_meta(self,attrs):
x=self.get_attr(attrs,'name')
ifx=="author":
self.SiteName=self.get_attr(attrs,'content')
defstart_input(self,attrs):
x=self.get_attr(attrs,'name')
#print "input name=",x
ifx=="tid":
self.TourneyId=self.get_attr(attrs,'value')
defstart_h1(self,attrs):
ifself.TourneyNameisNone:
self.save_bgn()
defend_h1(self):
ifself.TourneyNameisNone:
self.TourneyName=self.save_end()
defstart_div(self,attrs):
x=self.get_attr(attrs,'id')
ifx=="result":
self.parseResultsA=True
defend_div(self):# TODO: Can we get attrs in the END tag too? I don't know? Would be useful to make SURE we're closing the right div ..
ifself.parseResultsA:
self.parseResultsA=False# TODO: Should probably just make sure everything is false at this point, since we're not going to be having anything in the middle of a DIV.. oh well
defstart_td(self,attrs):
self.save_bgn()
defend_td(self):
x=self.save_end()
ifnotself.parseResultsA:
ifnotself.nextStartTimeandx=="Start:":
self.nextStartTime=True
elifself.nextStartTime:
self.TourneyStartTime=x
self.nextStartTime=False
ifnotself.nextEndTimeandx=="Finished:":
self.nextEndTime=True
elifself.nextEndTime:
self.TourneyEndTime=x
self.nextEndTime=False
ifnotself.nextGameTypeandx=="Game Type:":
self.nextGameType=True
elifself.nextGameType:
self.TourneyGameType=x
self.nextGameType=False
ifnotself.nextStructureandx=="Limit:":
self.nextStructure=True
elifself.nextStructure:
self.TourneyStructure=x
self.nextStructure=False
ifnotself.nextBuyInandx=="Buy In / Fee:":
self.nextBuyIn=True
elifself.nextBuyIn:
self.TourneyBuyIn=x# TODO: Further parse the fee from this