def getInfoFromEmail(emailData):
msgTextList = getEmailText(emailData[0][1])
for msgText in msgTextList:
confNum = getConfNum(msgText)
# see if there are multiple itineraries
msgTextSplit = msgText.split()
if confNum in msgTextSplit:
confNumIndex = msgTextSplit.index(confNum)
else:
confNumIndex = msgTextSplit.index('*'+confNum+'*')
firstName = msgTextSplit[confNumIndex+1]
lastName = msgTextSplit[confNumIndex+2]
if 'Passenger(s)' in firstName:
# See if there is a / in the name
if '/' in lastName:
firstName = lastName[lastName.index('/')+1:]
lastName = lastName[0:lastName.index('/')]
else:
print("PROBLEM PARSING THE FIRST AND LAST NAMES!")
elif msgTextSplit[confNumIndex+4] == 'Date':
lastName = msgTextSplit[confNumIndex+3]
print("Make sure user used a middle initial")
# see if there are < formatting issues
if firstName == '>':
firstName = msgTextSplit[confNumIndex+2]
lastName = msgTextSplit[confNumIndex+4]
if lastName == '>':
print("AAAH")
print(msgTextSplit[confNumIndex+3])
lastName = msgTextSplit[confNumIndex+3]
possible2ndConf = msgTextSplit[confNumIndex+3][1:-1]
if len(possible2ndConf) == 6 and not enchant.Dict("en_US").check(possible2ndConf):
confNum = [confNum,str(possible2ndConf)]
firstName = [firstName, str(msgTextSplit[confNumIndex+4])]
lastName = [lastName, str(msgTextSplit[confNumIndex+5])]
else:
confNum = [confNum]
firstName = [firstName]
lastName = [lastName]
# get the time you need to check in
checkInTime = getCheckInTime(msgText)
checkInDate = getCheckInDate(msgText)
checkInCity = getCheckInCity(msgText)
try:
infoList = []
for j in xrange(len(checkInDate)):
for i in xrange(len(firstName)):
info = {'confNum':confNum[i],
'firstName':firstName[i],
'lastName':lastName[i],
'datetime':parser.parse(checkInDate[j] + ' ' + \
checkInTime[j]),
'city':checkInCity[j]}
infoList.append(info)
except:
infoList = []
print('info from email:')
print(infoList)
return infoList
评论列表
文章目录