ImapFetcher: Give some more meaningful output

This commit is contained in:
Worros 2010-09-05 01:14:08 +08:00
parent 7ac652c12e
commit edefd3ffb9

View File

@ -26,6 +26,7 @@ import re
import Configuration import Configuration
import Database import Database
from Exceptions import FpdbParseError
import SQL import SQL
import Options import Options
import PokerStarsSummary import PokerStarsSummary
@ -72,26 +73,34 @@ def run(config, db):
response, searchData = server.search(None, "SUBJECT", "PokerStars Tournament History Request") response, searchData = server.search(None, "SUBJECT", "PokerStars Tournament History Request")
for messageNumber in searchData[0].split(" "): for messageNumber in searchData[0].split(" "):
response, headerData = server.fetch(messageNumber, "(BODY[HEADER.FIELDS (SUBJECT)])") response, headerData = server.fetch(messageNumber, "(BODY[HEADER.FIELDS (SUBJECT)])")
#print "response to fetch subject:",response
if response!="OK": if response!="OK":
raise error #TODO: show error message raise error #TODO: show error message
neededMessages.append(("PS", messageNumber)) neededMessages.append(("PS", messageNumber))
print "ImapFetcher: Found %s messages to fetch" %(len(neededMessages))
if (len(neededMessages)==0): if (len(neededMessages)==0):
raise error #TODO: show error message raise error #TODO: show error message
for messageData in neededMessages:
errors = 0
for i, messageData in enumerate(neededMessages, start=1):
print "Retrieving message %s" % i
response, bodyData = server.fetch(messageData[1], "(UID BODY[TEXT])") response, bodyData = server.fetch(messageData[1], "(UID BODY[TEXT])")
bodyData=bodyData[0][1] bodyData=bodyData[0][1]
if response!="OK": if response!="OK":
raise error #TODO: show error message raise error #TODO: show error message
if messageData[0]=="PS": if messageData[0]=="PS":
summaryTexts=(splitPokerStarsSummaries(bodyData)) summaryTexts=(splitPokerStarsSummaries(bodyData))
for summaryText in summaryTexts: print "Found %s summaries in email" %(len(summaryTexts))
result=PokerStarsSummary.PokerStarsSummary(db=db, config=config, siteName=u"PokerStars", summaryText=summaryText, builtFrom = "IMAP") for j, summaryText in enumerate(summaryTexts, start=1):
#print "finished importing a PS summary with result:",result try:
#TODO: count results and output to shell like hand importer does result=PokerStarsSummary.PokerStarsSummary(db=db, config=config, siteName=u"PokerStars", summaryText=summaryText, builtFrom = "IMAP")
except FpdbParseError, e:
errors += 1
print "Finished importing %s/%s PS summaries" %(j, len(summaryTexts))
print _("completed running Imap import, closing server connection") print _("Completed running Imap import, closing server connection")
print _("Errors: %s" % errors)
#finally: #finally:
# try: # try:
server.close() server.close()
@ -121,9 +130,6 @@ def runFake(db, config, infile):
result = PokerStarsSummary.PokerStarsSummary(db=db, config=config, siteName=u"PokerStars", summaryText=summary, builtFrom = "file") result = PokerStarsSummary.PokerStarsSummary(db=db, config=config, siteName=u"PokerStars", summaryText=summary, builtFrom = "file")
print "DEBUG: Processed: %s: tournNo: %s" % (result.tourneyId, result.tourNo) print "DEBUG: Processed: %s: tournNo: %s" % (result.tourneyId, result.tourNo)
def splitPokerStarsSummaries(emailText):
splitSummaries=emailText.split("\nPokerStars Tournament #")[1:]
def main(argv=None): def main(argv=None):
if argv is None: if argv is None: