# Copyright (c) 2009 Eric Blade, and the FPDB team.
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU Affero General Public License as published by
#the Free Software Foundation, version 3 of the License.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU Affero General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
#In the "official" distribution you can find the license in
#agpl-3.0.txt in the docs folder of the package.
importurllib,htmllib,formatter
classAppURLopener(urllib.FancyURLopener):
version="Free Poker Database/0.12+"
urllib._urlopener=AppURLopener()
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