Imap/PSSummary: Update and refactor
Primarily to make FTP summaries read from file.
This commit is contained in:
parent
d66ae965a1
commit
2514b424c8
|
@ -30,6 +30,7 @@ from Exceptions import FpdbParseError
|
||||||
import SQL
|
import SQL
|
||||||
import Options
|
import Options
|
||||||
import PokerStarsSummary
|
import PokerStarsSummary
|
||||||
|
import FullTiltPokerSummary
|
||||||
|
|
||||||
|
|
||||||
import locale
|
import locale
|
||||||
|
@ -44,12 +45,23 @@ else:
|
||||||
except IOError:
|
except IOError:
|
||||||
def _(string): return string
|
def _(string): return string
|
||||||
|
|
||||||
def splitPokerStarsSummaries(emailText):
|
def splitPokerStarsSummaries(summaryText):
|
||||||
splitSummaries=emailText.split("\nPokerStars Tournament #")[1:]
|
re_SplitTourneys = PokerStarsSummary.PokerStarsSummary.re_SplitTourneys
|
||||||
for i in range(len(splitSummaries)):
|
splitSummaries = re.split(re_SplitTourneys, summaryText)
|
||||||
splitSummaries[i]="PokerStars Tournament #"+splitSummaries[i]
|
|
||||||
|
if len(splitSummaries) <= 1:
|
||||||
|
print _("DEBUG: re_SplitTourneyss isn't matching")
|
||||||
|
|
||||||
|
return splitSummaries
|
||||||
|
|
||||||
|
def splitFullTiltSummaries(summaryText):
|
||||||
|
re_SplitTourneys = FullTiltPokerSummary.FullTiltPokerSummary.re_SplitTourneys
|
||||||
|
splitSummaries = re.split(re_SplitTourneys, summaryText)
|
||||||
|
|
||||||
|
if len(splitSummaries) <= 1:
|
||||||
|
print _("DEBUG: re_SplitTourneyss isn't matching")
|
||||||
|
|
||||||
return splitSummaries
|
return splitSummaries
|
||||||
#end def emailText
|
|
||||||
|
|
||||||
def run(config, db):
|
def run(config, db):
|
||||||
#print "start of IS.run"
|
#print "start of IS.run"
|
||||||
|
@ -107,27 +119,50 @@ def run(config, db):
|
||||||
|
|
||||||
print _("Errors: %s" % errors)
|
print _("Errors: %s" % errors)
|
||||||
|
|
||||||
def readFile(filename):
|
def readFile(filename, options):
|
||||||
kodec = "utf8"
|
codepage = ["utf8"]
|
||||||
|
whole_file = None
|
||||||
|
if options.hhc == "PokerStars":
|
||||||
|
codepage = PokerStarsSummary.PokerStarsSummary.codepage
|
||||||
|
elif options.hhc == "Full Tilt Poker":
|
||||||
|
codepage = FullTiltPokerSummary.FullTiltPokerSummary.codepage
|
||||||
|
|
||||||
|
for kodec in codepage:
|
||||||
|
#print "trying", kodec
|
||||||
|
try:
|
||||||
in_fh = codecs.open(filename, 'r', kodec)
|
in_fh = codecs.open(filename, 'r', kodec)
|
||||||
whole_file = in_fh.read()
|
whole_file = in_fh.read()
|
||||||
in_fh.close()
|
in_fh.close()
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
return whole_file
|
return whole_file
|
||||||
|
|
||||||
|
def runFake(db, config, options):
|
||||||
|
summaryText = readFile(options.infile, options)
|
||||||
|
importSummaries(db, config,[summaryText], options=options)
|
||||||
|
|
||||||
|
def importSummaries(db, config, summaries, options = None):
|
||||||
def runFake(db, config, infile):
|
# TODO: At this point we should have:
|
||||||
summaryText = readFile(infile)
|
# - list of strings to process
|
||||||
importSummaries(db, config,[summaryText])
|
# - The sitename OR specialised TourneySummary object
|
||||||
|
# Using options is pretty ugly
|
||||||
def importSummaries(db, config, summaries):
|
|
||||||
errors = 0
|
errors = 0
|
||||||
for summaryText in summaries:
|
for summaryText in summaries:
|
||||||
|
# And we should def be using a 'Split' from the site object
|
||||||
|
if options.hhc == "PokerStars":
|
||||||
summaryTexts=(splitPokerStarsSummaries(summaryText))
|
summaryTexts=(splitPokerStarsSummaries(summaryText))
|
||||||
|
elif options.hhc == "Full Tilt Poker":
|
||||||
|
summaryTexts=(splitFullTiltSummaries(summaryText))
|
||||||
|
|
||||||
print "Found %s summaries in email" %(len(summaryTexts))
|
print "Found %s summaries in email" %(len(summaryTexts))
|
||||||
for j, summaryText in enumerate(summaryTexts, start=1):
|
for j, summaryText in enumerate(summaryTexts, start=1):
|
||||||
try:
|
try:
|
||||||
result=PokerStarsSummary.PokerStarsSummary(db=db, config=config, siteName=u"PokerStars", summaryText=summaryText, builtFrom = "IMAP")
|
if options.hhc == "PokerStars":
|
||||||
|
PokerStarsSummary.PokerStarsSummary(db=db, config=config, siteName=u"PokerStars", summaryText=summaryText, builtFrom = "IMAP")
|
||||||
|
elif options.hhc == "Full Tilt Poker":
|
||||||
|
FullTiltPokerSummary.FullTiltPokerSummary(db=db, config=config, siteName=u"Fulltilt", summaryText=summaryText, builtFrom = "IMAP")
|
||||||
except FpdbParseError, e:
|
except FpdbParseError, e:
|
||||||
errors += 1
|
errors += 1
|
||||||
print _("Finished importing %s/%s PS summaries") %(j, len(summaryTexts))
|
print _("Finished importing %s/%s PS summaries") %(j, len(summaryTexts))
|
||||||
|
@ -146,6 +181,10 @@ def main(argv=None):
|
||||||
print _("USAGE:")
|
print _("USAGE:")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
if options.hhc == "PokerStarsToFpdb":
|
||||||
|
print _("Need to define a converter")
|
||||||
|
exit(0)
|
||||||
|
|
||||||
# These options should really come from the OptionsParser
|
# These options should really come from the OptionsParser
|
||||||
config = Configuration.Config()
|
config = Configuration.Config()
|
||||||
db = Database.Database(config)
|
db = Database.Database(config)
|
||||||
|
@ -156,7 +195,7 @@ def main(argv=None):
|
||||||
settings.update(config.get_default_paths())
|
settings.update(config.get_default_paths())
|
||||||
db.recreate_tables()
|
db.recreate_tables()
|
||||||
|
|
||||||
runFake(db, config, options.infile)
|
runFake(db, config, options)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
|
|
@ -57,7 +57,7 @@ class PokerStarsSummary(TourneySummary):
|
||||||
'LS' : "\$|\xe2\x82\xac|" # legal currency symbols - Euro(cp1252, utf-8)
|
'LS' : "\$|\xe2\x82\xac|" # legal currency symbols - Euro(cp1252, utf-8)
|
||||||
}
|
}
|
||||||
|
|
||||||
re_SplitGames = re.compile("^PokerStars")
|
re_SplitTourneys = re.compile("PokerStars Tournament ")
|
||||||
|
|
||||||
re_TourNo = re.compile("\#(?P<TOURNO>[0-9]+),")
|
re_TourNo = re.compile("\#(?P<TOURNO>[0-9]+),")
|
||||||
|
|
||||||
|
@ -81,6 +81,8 @@ class PokerStarsSummary(TourneySummary):
|
||||||
|
|
||||||
re_DateTime = re.compile("\[(?P<Y>[0-9]{4})\/(?P<M>[0-9]{2})\/(?P<D>[0-9]{2})[\- ]+(?P<H>[0-9]+):(?P<MIN>[0-9]+):(?P<S>[0-9]+)")
|
re_DateTime = re.compile("\[(?P<Y>[0-9]{4})\/(?P<M>[0-9]{2})\/(?P<D>[0-9]{2})[\- ]+(?P<H>[0-9]+):(?P<MIN>[0-9]+):(?P<S>[0-9]+)")
|
||||||
|
|
||||||
|
codepage = ["utf-8"]
|
||||||
|
|
||||||
def parseSummary(self):
|
def parseSummary(self):
|
||||||
m = self.re_TourneyInfo.search(self.summaryText)
|
m = self.re_TourneyInfo.search(self.summaryText)
|
||||||
if m == None:
|
if m == None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user