Gmail API but no
This commit is contained in:
parent
69b5bd9a81
commit
4c3f00994a
2
waterbill/.gitignore
vendored
Normal file
2
waterbill/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
client_secrets.json
|
||||||
|
.venv/
|
1
waterbill/requirements.txt
Normal file
1
waterbill/requirements.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
google-api-python-client
|
44
waterbill/waterbill.py
Normal file
44
waterbill/waterbill.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
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…
Reference in New Issue
Block a user