本文整理汇总了Python中gmail.Gmail.label方法的典型用法代码示例。如果您正苦于以下问题:Python Gmail.label方法的具体用法?Python Gmail.label怎么用?Python Gmail.label使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gmail.Gmail
的用法示例。
在下文中一共展示了Gmail.label方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Gmail
# 需要导入模块: from gmail import Gmail [as 别名]
# 或者: from gmail.Gmail import label [as 别名]
if sys.argv[1]=='recive':
g = Gmail()
g.login('gmail_login', 'gmail_pass')
# mark the letters without html markup as Normal
messages = g.inbox().mail()
for message in messages:
message.fetch()
message_body=message.body.split()
message_body=("".join(message_body)).strip()
if this_html(message_body)==False:
message.add_label("Normal")
# all letters marked as Normal
if sys.argv[2]=='all':
all_messages=g.label("Normal").mail()
for mes in all_messages:
mes.fetch()
mes.read() # mark letter as read
print mes.fr #from whom
print mes.body # main text (body) of e-mail
print "--------------------------------"
# new (unread) letters marked as Normal
if sys.argv[2]=='new':
new_messages=g.label("Normal").mail(unread=True)
for new_mes in new_messages:
new_mes.fetch()
new_mes.read()
print new_mes.fr
print new_mes.body
示例2: ReuseParser
# 需要导入模块: from gmail import Gmail [as 别名]
# 或者: from gmail.Gmail import label [as 别名]
#.........这里部分代码省略.........
self.appendToLog("could not find location _%s_ in lookup dict" % guess.generalLocation)
theReuseItem.guess_found=False
return theReuseItem
def batchSaveList(self, listOfParseObjects):
if len(listOfParseObjects)==0:
return;
print 'batch saving objects'
self.appendToLog('batch saving %d objects' % len(listOfParseObjects))
#batch save a list of parseobjects. the batch limit is 50!
batcher = ParseBatcher()
batchLimit = 50
while len(listOfParseObjects)> 0:
#save the first @batchLimit amount of objects
batcher.batch_save(listOfParseObjects[0:batchLimit])
#clear the list of those saved objects
listOfParseObjects = listOfParseObjects[batchLimit:]
def handleReplyEmail(self, replyList):
batchItemList = []
for email in replyList:
#find the old post and set the claimed field!
existingItems= ReuseItem.Query.all().filter(email_id = email.thread_id).limit(1) #get only 1 post
for item in existingItems:
#update the claimed field
item.claimed = True
batchItemList.append(item)
logPost = "set post _%s_ to claimed based on post _%s_" % (item.email_subject[0:32], email.body[0:32])
self.appendToLog( logPost )
if self.isDebugMode: print logPost
#batch save those objects now!
self.batchSaveList(batchItemList)
def yesItShould(self):
#runs the whole shebang
self.appendToLog(" ")
self.appendToLog("running the whole shebang")
# #the gmail object, maybe
# g = Gmail()
self.g = Gmail()
self.g.login("radixdeveloper", "whereisstrauss")
# #the location object
# loc = Locator()
emails = self.g.label("reuse").mail(unread=True)
#batcher lists for parse
parseObjectBatchList = []
# claimedEmailsBatchList = []
for email in emails:
if self.isDebugMode:
print "="*8
print " "
email.fetch()
#don't read if testing
if not self.isDebugMode: email.read()
#if it is a reply email, ignore it
if isReplyEmail(email):
if self.isDebugMode: print "skipping: "+email.subject #+ " "+email.body
# if (util.isClaimedEmail(email)):
# claimedEmailsBatchList.append(email)
continue
#print the first snippet of the email
print(email.subject[0:self.logSnippetLength])
# print(email.body)
self.appendToLog(email.subject[0:self.logSnippetLength])
#make the guess
locationGuess = self.loc.makeGuessByEmail(email)
self.appendToLog("guess location = %s" % locationGuess.__str__())
if self.isDebugMode: print("guess location = %s" % locationGuess.__str__())
#create the item and save for later batch saving
theReuseItem = self.createReuseItem(email,locationGuess)
parseObjectBatchList.append(theReuseItem)
#batch save the objects we created above
self.batchSaveList(parseObjectBatchList)
# #deal with the reply emails AFTER saving the existing ones above
# self.handleReplyEmail(claimedEmailsBatchList)
print 'done'
self.appendToLog("done with run, logging out of gmail.")
self.g.logout()