cat-town
Dan Buch 8 years ago
parent 4c3f00994a
commit 14fa993a97
No known key found for this signature in database
GPG Key ID: FAEF12936DD3E3EC

@ -1,2 +0,0 @@
client_secrets.json
.venv/

@ -1 +0,0 @@
google-api-python-client

@ -1,44 +0,0 @@
import os
import sys
from apiclient import discovery
from oauth2client import client
from oauth2client import tools
def main():
config_dir = get_config_dir()
if not os.path.exists(config_dir):
os.makedirs(config_dir)
creds_path = os.path.join(config_dir, 'creds.json')
store = oauth2client.file.Storage(creds_path)
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets(
get_client_secrets(),
scope='https://www.googleapis.com/auth/gmail.readonly'
)
flow.user_agent = 'Buch Bedford Water Bill'
creds = tools.run(flow, store)
http = creds.authorize(httplib2.Http())
service = discovery.build('gmail', 'v1', http=http)
results = service.users().messages().list(userId='me').execute()
labels = results.get('labels', [])
return 0
def get_client_secrets():
return os.environ.get('CLIENT_SECRETS_JSON', 'client_secrets.json')
def get_config_dir():
return os.path.expanduser(os.environ.get('config_dir', '~/.config/bbwb'))
if __name__ == '__main__':
sys.exit(main())
Loading…
Cancel
Save