copied bit of error handling from Carl
This commit is contained in:
parent
0ecd19fbdf
commit
1bf3827921
|
@ -30,25 +30,27 @@ def splitPokerStarsSummaries(emailText):
|
||||||
return splitSummaries
|
return splitSummaries
|
||||||
#end def emailText
|
#end def emailText
|
||||||
|
|
||||||
#TODO: move all these into the config file. until then usage is: ./ImapSummaries.py YourImapHost YourImapUser YourImapPw
|
if __name__ == '__main__':
|
||||||
configHost=sys.argv[1]
|
#TODO: move all these into the config file. until then usage is: ./ImapSummaries.py YourImapHost YourImapUser YourImapPw
|
||||||
configUser=sys.argv[2]
|
configHost=sys.argv[1]
|
||||||
configPw=sys.argv[3]
|
configUser=sys.argv[2]
|
||||||
#TODO: specify folder, whether to use SSL
|
configPw=sys.argv[3]
|
||||||
|
#TODO: specify folder, whether to use SSL
|
||||||
|
|
||||||
server = IMAP4_SSL(configHost) #TODO: optionally non-SSL
|
try:
|
||||||
response = server.login(configUser, configPw) #TODO catch authentication error
|
server = IMAP4_SSL(configHost) #TODO: optionally non-SSL
|
||||||
#print "response to logging in:",response
|
response = server.login(configUser, configPw) #TODO catch authentication error
|
||||||
#print "server.list():",server.list() #prints list of folders
|
#print "response to logging in:",response
|
||||||
|
#print "server.list():",server.list() #prints list of folders
|
||||||
|
|
||||||
response = server.select("INBOX")
|
response = server.select("INBOX")
|
||||||
#print "response to selecting INBOX:",response
|
#print "response to selecting INBOX:",response
|
||||||
if response[0]!="OK":
|
if response[0]!="OK":
|
||||||
raise error #TODO: show error message
|
raise error #TODO: show error message
|
||||||
|
|
||||||
neededMessages=[]
|
neededMessages=[]
|
||||||
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
|
#print "response to fetch subject:",response
|
||||||
if response!="OK":
|
if response!="OK":
|
||||||
|
@ -56,9 +58,9 @@ for messageNumber in searchData[0].split(" "):
|
||||||
if headerData[1].find("Subject: PokerStars Tournament History Request - Last x")!=1:
|
if headerData[1].find("Subject: PokerStars Tournament History Request - Last x")!=1:
|
||||||
neededMessages.append(("PS", messageNumber))
|
neededMessages.append(("PS", messageNumber))
|
||||||
|
|
||||||
if (len(neededMessages)==0):
|
if (len(neededMessages)==0):
|
||||||
raise error #TODO: show error message
|
raise error #TODO: show error message
|
||||||
for messageData in neededMessages:
|
for messageData in neededMessages:
|
||||||
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":
|
||||||
|
@ -70,6 +72,11 @@ for messageData in neededMessages:
|
||||||
#print "result:",result
|
#print "result:",result
|
||||||
#TODO: count results and output to shell like hand importer does
|
#TODO: count results and output to shell like hand importer does
|
||||||
|
|
||||||
print "completed running Imap import, closing server connection"
|
print "completed running Imap import, closing server connection"
|
||||||
server.close()
|
finally:
|
||||||
server.logout()
|
try:
|
||||||
|
server.close()
|
||||||
|
finally:
|
||||||
|
pass
|
||||||
|
server.logout()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user