本文整理汇总了Python中gmail.Gmail.mailbox方法的典型用法代码示例。如果您正苦于以下问题:Python Gmail.mailbox方法的具体用法?Python Gmail.mailbox怎么用?Python Gmail.mailbox使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gmail.Gmail
的用法示例。
在下文中一共展示了Gmail.mailbox方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: doScrape
# 需要导入模块: from gmail import Gmail [as 别名]
# 或者: from gmail.Gmail import mailbox [as 别名]
def doScrape(Con, q):
try:
g = Gmail()
################ LOGIN #####################################
q.put(('Logging In', 5),)
logger.info("Logging In")
try:
g.login(Con.Username, Con.Password)
except AuthenticationError:
logger.exception(sys.exc_info())
q.put(('Login Failed', 100),)
return "AUTH_ERROR"
############################################################
################ GET LABEL MAILBOX #########################
mailbox = None
q.put(('Getting Mailbox', 10),)
logger.info("Getting Mailbox")
try:
if Con.Label.lower() == 'inbox':
mailbox = g.inbox()
else:
mailbox = g.mailbox(Con.Label)
except:
logger.exception(sys.exc_info())
q.put(('Problem in fetching Gmail Label', 100),)
return "LABEL_FETCH_ERROR"
if not mailbox:
q.put(('Gmail Label Not Found', 100),)
return "LABEL_NOT_FOUND"
############################################################
################ GET EMAILS ################################
mails = None
q.put(('Searching For Emails', 15),)
logger.info("Searching Emails")
try:
afterDate = Con.FromDate - timedelta(days=1)
beforeDate = Con.ToDate + timedelta(days=1)
mails = mailbox.mail(subject='Fiverr: Congrats! You have a new order',
after=afterDate, before=beforeDate)
mails.extend(mailbox.mail(subject='just ordered an Extra',
after=afterDate, before=beforeDate))
# mails = mailbox.mail(after=Con.FromDate, before=Con.ToDate)
except:
logger.exception(sys.exc_info())
q.put(('Problem in searching for emails', 100),)
return "EMAILS_FETCH_ERROR"
if len(mails) == 0:
q.put(('No Emails Found with search criteria', 100),)
return "NO_EMAIL_FOUND"
############################################################
################ FETCH EMAILS ##############################
q.put(('Fetching Emails', 20),)
logger.info("Scraping Order Data From Emails")
Con.Orders = []
logger.info("Num of Emails found: " + str(len(mails)))
try:
for mail in mails:
msg = "Fetching Email " + str(mails.index(mail)+1) + ' of ' + str(len(mails))
per = 20 + int((float(mails.index(mail)+1) * 100.0 * 0.6 / float(len(mails))))
q.put((msg, per),)
#logger.info(msg)
mail.fetch()
gmailEvents.extract_orders_from_email(mail, Con)
except:
logger.exception(sys.exc_info())
q.put(('Problem in fetching emails', 100),)
return "EMAIL_FETCH_ERROR"
############################################################
# return 'SUCCESS'
################ CALCULATE TOTAL AMOUNT ####################
q.put(('Calculating Total and Revenue', 85),)
logger.info("Calculating Total Amount")
gmailEvents.calculate_total_amount(Con)
############################################################
################ GENERATE XLS ##############################
q.put(('Generating XLS', 90),)
logger.info("Generating XLS")
gmailEvents.generate_xls(Con)
############################################################
q.put(('Logging Out of Gmail', 95),)
g.logout()
q.put(('SUCCESS', 100),)
return 'SUCCESS'
except:
if g:
g.logout()
logger.exception(sys.exc_info())
q.put(('Error Occurred', 100),)
return "ERROR"