2016-02-22 5 views
-2

Как получить количество непрочитанных сообщений gmail, используя безглавую малину pi с python?Количество непрочитанных сообщений gmail

Я использовал

from __future__ import print_function 
import httplib2 
import os 

from apiclient import discovery 
import oauth2client 
from oauth2client import client 
from oauth2client import tools 

try: 
    import argparse 
    flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args() 
except ImportError: 
    flags = None 

# If modifying these scopes, delete your previously saved credentials 
# at ~/.credentials/gmail-python-quickstart.json 
SCOPES = 'https://www.googleapis.com/auth/gmail.readonly' 
CLIENT_SECRET_FILE = 'client_secret.json' 
APPLICATION_NAME = 'Gmail API Python Quickstart' 


def get_credentials().... 
+2

Я не вижу каких-либо попыток осуществить их API в коде вы публикуемую. – tripleee

ответ

0
import imaplib 
import email 

def fetchUnreadEmails(profile, since=None, markRead=False, limit=None): 

    conn = imaplib.IMAP4_SSL('imap.gmail.com') 
    conn.debug = 0 
    conn.login(profile['gmail_address'], profile['gmail_password']) 
    conn.select(readonly=(not markRead)) 

    msgs = [] 
    (retcode, messages) = conn.search(None, '(UNSEEN)') 

    if retcode == 'OK' and messages != ['']: 
     numUnread = len(messages[0].split(' ')) 
     if limit and numUnread > limit: 
      return numUnread 

     for num in messages[0].split(' '): 
      # parse email RFC822 format 
      ret, data = conn.fetch(num, '(RFC822)') 
      msg = email.message_from_string(data[0][1]) 

      if not since or getDate(msg) > since: 
       msgs.append(msg) 
    conn.close() 
    conn.logout() 

    return msgs 

из jasperproject модуля Gmail

Смежные вопросы