Update for Gnome Shell 45+
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import os.path
|
||||
import json
|
||||
|
||||
from google.auth.transport.requests import Request
|
||||
from google.oauth2.credentials import Credentials
|
||||
@@ -37,7 +38,7 @@ creds = None
|
||||
def _initCreds():
|
||||
global creds
|
||||
if creds: return
|
||||
|
||||
|
||||
# The file token.json stores the user's access and refresh tokens, and is
|
||||
# created automatically when the authorization flow completes for the first
|
||||
# time.
|
||||
@@ -53,15 +54,21 @@ def _initCreds():
|
||||
creds = flow.run_local_server(port=0)
|
||||
# Save the credentials for the next run
|
||||
with open('token.json', 'w') as token:
|
||||
token.write(creds.to_json())
|
||||
|
||||
data = {}
|
||||
data['refresh_token'] = creds.refresh_token
|
||||
data['client_id'] = creds.client_id
|
||||
data['client_secret'] = creds.client_secret
|
||||
data['token_uri'] = creds.token_uri
|
||||
data['id_token'] = creds.id_token
|
||||
token.write(json.dumps(data))
|
||||
|
||||
def getUnreadMails():
|
||||
"""
|
||||
Get number of unread threads (that may contain multiple messages)
|
||||
"""
|
||||
|
||||
_initCreds()
|
||||
|
||||
|
||||
service = build('gmail', 'v1', credentials=creds)
|
||||
pageToken = ''
|
||||
threads = set()
|
||||
@@ -69,6 +76,7 @@ def getUnreadMails():
|
||||
results = service.users().messages().list(userId='me', labelIds=['UNREAD'],\
|
||||
includeSpamTrash=False, pageToken=pageToken)\
|
||||
.execute()
|
||||
if not 'messages' in results.keys(): continue
|
||||
threads = threads.union(set([k['threadId'] for k in results['messages']]))
|
||||
# Loop over all result pages (100 results per page by default)
|
||||
pageToken = results.get('nextPageToken', '')
|
||||
|
||||
Reference in New Issue
Block a user