ImapFetcher: refactor the import part from the IMAP connection
This commit is contained in:
parent
7f61fba314
commit
58de54560d
|
@ -82,7 +82,7 @@ def run(config, db):
|
||||||
if (len(neededMessages)==0):
|
if (len(neededMessages)==0):
|
||||||
raise error #TODO: show error message
|
raise error #TODO: show error message
|
||||||
|
|
||||||
errors = 0
|
email_bodies = []
|
||||||
for i, messageData in enumerate(neededMessages, start=1):
|
for i, messageData in enumerate(neededMessages, start=1):
|
||||||
print "Retrieving message %s" % i
|
print "Retrieving message %s" % i
|
||||||
response, bodyData = server.fetch(messageData[1], "(UID BODY[TEXT])")
|
response, bodyData = server.fetch(messageData[1], "(UID BODY[TEXT])")
|
||||||
|
@ -90,23 +90,22 @@ def run(config, db):
|
||||||
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))
|
email_bodies.append(bodyData)
|
||||||
print "Found %s summaries in email" %(len(summaryTexts))
|
|
||||||
for j, summaryText in enumerate(summaryTexts, start=1):
|
|
||||||
try:
|
|
||||||
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 _("Errors: %s" % errors)
|
|
||||||
#finally:
|
#finally:
|
||||||
# try:
|
# try:
|
||||||
server.close()
|
server.close()
|
||||||
# finally:
|
# finally:
|
||||||
# pass
|
# pass
|
||||||
server.logout()
|
server.logout()
|
||||||
|
print _("Completed retrieving IMAP messages, closing server connection")
|
||||||
|
|
||||||
|
errors = 0
|
||||||
|
if len(email_bodies) > 0:
|
||||||
|
errors = importSummaries(db, config, email_bodies)
|
||||||
|
else:
|
||||||
|
print _("No Tournament summaries found.")
|
||||||
|
|
||||||
|
print _("Errors: %s" % errors)
|
||||||
|
|
||||||
def readFile(filename):
|
def readFile(filename):
|
||||||
kodec = "utf8"
|
kodec = "utf8"
|
||||||
|
@ -119,16 +118,21 @@ def readFile(filename):
|
||||||
|
|
||||||
def runFake(db, config, infile):
|
def runFake(db, config, infile):
|
||||||
summaryText = readFile(infile)
|
summaryText = readFile(infile)
|
||||||
# This regex should be part of PokerStarsSummary
|
importSummaries(db, config,[summaryText])
|
||||||
re_SplitGames = re.compile("PokerStars Tournament ")
|
|
||||||
summaryList = re.split(re_SplitGames, summaryText)
|
|
||||||
|
|
||||||
if len(summaryList) <= 1:
|
def importSummaries(db, config, summaries):
|
||||||
print _("DEBUG: re_SplitGames isn't matching")
|
errors = 0
|
||||||
|
for summaryText in summaries:
|
||||||
|
summaryTexts=(splitPokerStarsSummaries(summaryText))
|
||||||
|
print "Found %s summaries in email" %(len(summaryTexts))
|
||||||
|
for j, summaryText in enumerate(summaryTexts, start=1):
|
||||||
|
try:
|
||||||
|
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))
|
||||||
|
|
||||||
for summary in summaryList[1:]:
|
return errors
|
||||||
result = PokerStarsSummary.PokerStarsSummary(db=db, config=config, siteName=u"PokerStars", summaryText=summary, builtFrom = "file")
|
|
||||||
print _("DEBUG: Processed: %s: tournNo: %s") % (result.tourneyId, result.tourNo)
|
|
||||||
|
|
||||||
|
|
||||||
def main(argv=None):
|
def main(argv=None):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user