Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
from datetime import datetime,timedelta
try:
import argparse
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
flags = Nones
SCOPES = 'https://www.googleapis.com/auth/calendar'
store = file.Storage('storage.json')
creds = store.get()
tagged_json = {"date" :"2016-06-25 10:00:00",
"event" : "Call mom"}
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store, flags) \
if flags else tools.run(flow, store)
CAL = build('calendar', 'v3', http=creds.authorize(Http()))
:param str|Path token_path:
"""
range = '{}!A2:D'.format(sheet_name)
if clientsecrets_path is None:
clientsecrets_path = Path('user/google/credentials.json')
if not clientsecrets_path.parent.exists():
clientsecrets_path.parent.mkdir()
if token_path is None:
token_path = clientsecrets_path.with_name('token.json')
store = file.Storage(str(token_path))
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets(str(clientsecrets_path), self.SCOPES)
creds = tools.run_flow(flow, store)
service = build('sheets', 'v4', http=creds.authorize(Http()))
# Call the Sheets API
result = service.spreadsheets().values().get(spreadsheetId=spreadsheet_id,
range=range).execute()
values = result.get('values', [])
self.data = list()
if not values:
print('No data found.')
else:
for row in values:
self.data.append(CardTuple(*row))
# Do OAuth2 authentication
flow = flow_from_clientsecrets(
client_secrets_file,
message=missing_secrets_message,
scope=YoutubeAdapter.YOUTUBE_READ_WRITE_SCOPE,
redirect_uri=YoutubeAdapter.REDIRECT_URI
)
storage = Storage(config_path + "oauth2.json")
credentials = storage.get()
if credentials is None or credentials.invalid:
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
parents=[oauth2client.tools.argparser],
)
flags = parser.parse_args()
credentials = run_flow(flow, storage, flags)
# Create the service to use throughout the script
self.service = build(
YoutubeAdapter.YOUTUBE_API_SERVICE_NAME,
YoutubeAdapter.YOUTUBE_API_VERSION,
developerKey=api_key,
http=credentials.authorize(httplib2.Http())
)
def get_service(self):
SCOPES = 'https://www.googleapis.com/auth/gmail.readonly'
store = file.Storage('credentials.json')
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
credentials = tools.run_flow(flow, store)
http = credentials.authorize(httplib2.Http())
return discovery.build('gmail', 'v1', http=http)
"""
home_dir = os.path.expanduser('~')
credential_dir = os.path.join(home_dir, '.credentials')
if not os.path.exists(credential_dir):
os.makedirs(credential_dir)
credential_path = os.path.join(credential_dir,
'calendar-alfred-today.json')
store = oauth2client.file.Storage(credential_path)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
flow.user_agent = APPLICATION_NAME
if flags:
credentials = tools.run_flow(flow, store, flags)
else: # Needed only for compatibility with Python 2.6
credentials = tools.run(flow, store)
print('Storing credentials to ' + credential_path)
return credentials
from __future__ import print_function
import httplib2
import os
from apiclient import discovery
import oauth2client
from oauth2client import client
from oauth2client import tools
import json
import datetime
DEBUG = False
try:
import argparse
flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args()
except ImportError:
flags = None
SCOPES = 'https://www.googleapis.com/auth/calendar'
CLIENT_SECRET_FILE = 'client_secret.json'
APPLICATION_NAME = 'gyft'
def next_weekday(d, weekday):
days_ahead = weekday - d.weekday()
if days_ahead <= 0: # Target day already happened this week
days_ahead += 7
return d + datetime.timedelta(days_ahead)
def get_credentials():
def get_arguments(argv, desc, parents=None):
"""Validates and parses command line arguments.
Args:
argv: list of strings, the command-line parameters of the application.
desc: string, a description of the sample being executed.
parents: list of argparse.ArgumentParser, additional command-line parsers.
Returns:
The parsed command-line arguments.
"""
# Include the default oauth2client argparser
parent_parsers = [tools.argparser]
if parents:
parent_parsers.extend(parents)
parser = argparse.ArgumentParser(
description=desc,
formatter_class=argparse.RawDescriptionHelpFormatter,
parents=parent_parsers)
return parser.parse_args(argv[1:])
def get_credentials(self):
storage_path = '.' + os.path.splitext(os.path.basename(__file__))[0] + '.credentials'
storage = Storage(storage_path)
credentials = storage.get() if os.path.exists(storage_path) else None
if credentials is None or credentials.invalid:
flow = flow_from_clientsecrets(self.credentials_path,
scope=self.SCOPE,
redirect_uri=self.REDIRECT_URI)
flow.params['access_type'] = 'offline'
flow.params['approval_prompt'] = 'force'
credentials = tools.run_flow(flow, storage)
return credentials
def main(argv):
# Parse the command-line flags.
flags = parser.parse_args(argv[1:])
# If the credentials don't exist or are invalid run through the native client
# flow. The Storage object will ensure that if successful the good
# credentials will get written back to the file.
storage = file.Storage('sample.dat')
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = tools.run_flow(FLOW, storage, flags)
# Create an httplib2.Http object to handle our HTTP requests and authorize it
# with our good Credentials.
http = httplib2.Http()
http = credentials.authorize(http)
# Construct the service object for the interacting with the Compute Engine API.
service = discovery.build('compute', 'v1', http=http)
print 'Success! Now add code here.'