Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, url, key_fname):
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name(key_fname, scope)
self.gc = gspread.authorize(credentials)
self.wks = self.gc.open_by_url(url)
self.worksheet = self.wks.get_worksheet(0)
def get_lab_manifest():
json_key = json.load(open("/home/gpratt/ipython_notebook/public clip-588adbc137f3.json"))
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_dict(json_key, scope)
gc = gspread.authorize(credentials)
sht1 = gc.open_by_url("https://docs.google.com/spreadsheets/d/1ZU2mQh54jentqvhR_oMnviLGWR8Nw_x338gULzKjNDI/edit#gid=0")
ws = sht1.worksheet("Sheet1")
list_of_lists = ws.get_all_values()
manifest = pd.DataFrame(list_of_lists[1:], columns=list_of_lists[0])
manifest.is_encode = manifest.is_encode == "TRUE"
manifest.is_4000 = manifest.is_4000 == "TRUE"
manifest.method_Paper_flag = manifest.Method_Paper_flag == "TRUE"
manifest['exp_id'] = manifest.ENCODE_ID.apply(lambda x: x.split("_")[0])
manifest = manifest.drop(u'', axis=1) #Drops empty columns to try and get rid of a bug
return manifest
import logging
import os
import random
import socket
import ssl
import time
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from googleapiclient.http import MediaFileUpload, MediaIoBaseUpload, MediaIoBaseDownload, MediaUpload
from oauth2client import GOOGLE_TOKEN_URI
from oauth2client.client import GoogleCredentials
try:
from oauth2client.service_account import ServiceAccountCredentials
ServiceAccountCredentials_from_dict = ServiceAccountCredentials.from_json_keyfile_dict
except ImportError:
from oauth2client.service_account import _ServiceAccountCredentials
def ServiceAccountCredentials_from_dict(credentials):
return _ServiceAccountCredentials(
service_account_id=credentials["client_id"],
service_account_email=credentials["client_email"],
private_key_id=credentials["private_key_id"],
private_key_pkcs8_text=credentials["private_key"],
scopes=[])
from ..dates import parse_timestamp
from ..errors import FileNotFoundFromStorageError, InvalidConfigurationError
from .base import BaseTransfer, get_total_memory, KEY_TYPE_PREFIX, KEY_TYPE_OBJECT, IterKeyItem
# Configure the flask app
app.config.from_object("croplands_api.config." + config)
# initialize all of the extensions
jwt.init_app(app)
celery.init_app(app)
db.init_app(app)
limiter.init_app(app)
cache.init_app(app)
compress.init_app(app)
mail.init_app(app)
api.init_app(app, flask_sqlalchemy_db=db)
# initialize google earth engine
ee.Initialize(ServiceAccountCredentials._from_parsed_json_keyfile(
app.config['GOOGLE_SERVICE_ACCOUNT'],
scopes=app.config['GOOGLE_SERVICE_ACCOUNT_SCOPES']))
# import and register all of the blueprints
from croplands_api.views.public import public
from croplands_api.views.auth import auth
from croplands_api.views.gee import gee
from croplands_api.views.aws import aws
from croplands_api.views.upload import upload
from croplands_api.views.stats import stats_blueprint
from croplands_api.views.data import data_blueprint
app.register_blueprint(public)
app.register_blueprint(gee)
app.register_blueprint(aws)
app.register_blueprint(auth)
#!/usr/bin/env python
from __future__ import print_function
from oauth2client.service_account import ServiceAccountCredentials
from googleapiclient.discovery import build
from pystache import Renderer
from httplib2 import Http
import csv
import json
__version__ = '1.0.0'
scopes = ['https://www.googleapis.com/auth/gmail.settings.basic']
credentials = ServiceAccountCredentials.from_json_keyfile_name('keyfile.json', scopes)
def change_signature(email, name, title):
delegated_credentials = credentials.create_delegated(email)
http_auth = delegated_credentials.authorize(Http())
gmail = build('gmail', 'v1', http=http_auth)
send_as_body = {
'signature': Renderer().render_path('template.mustache', {
'name': name,
'title': title
})
}
print('Changing signature for %s' % email)
gmail.users().settings().sendAs().update(
userId='me',
def get_service(api_name, api_version, scopes, key_file_location, service_account_email):
"""Get a service that communicates to a Google API.
Args:
api_name: The name of the api to connect to.
api_version: The api version to connect to.
scope: A list auth scopes to authorize for the application.
key_file_location: The path to a valid service account p12 key file.
service_account_email: The service account email address.
Returns:
A service that is connected to the specified API.
"""
credentials = ServiceAccountCredentials.from_p12_keyfile(
service_account_email,
key_file_location,
scopes=scopes
)
http = credentials.authorize(httplib2.Http())
# Build the service object.
service = build(api_name, api_version, http=http)
return service
def CredentialsFromAdcDict(json_key):
"""Creates credentials object from a dict of application default creds."""
if 'client_email' not in json_key:
raise BadCredentialJsonFileException(
'The .json key file is not in a valid format.')
creds = service_account.ServiceAccountCredentials.from_json_keyfile_dict(
json_key, scopes=config.CLOUDSDK_SCOPES)
# User agent needs to be set separately, see
# https://github.com/google/oauth2client/issues/445
# pylint: disable=protected-access
creds.user_agent = creds._user_agent = config.CLOUDSDK_USER_AGENT
return creds
def setup_credentials():
scope = ['https://spreadsheets.google.com/feeds']
if on_heroku:
keyfile_dict = setup_keyfile_dict()
credentials = ServiceAccountCredentials.from_json_keyfile_dict(keyfile_dict, scope)
else:
credentials = ServiceAccountCredentials.from_json_keyfile_name('My Project-3b0bc29d35d3.json', scope)
gc = gspread.authorize(credentials)
wks = gc.open_by_key("1GnVhFp0s28HxAEOP6v7kmfmt3yPL_TGJSV2mcn1RPMY").sheet1
return wks
def get_auth_via_service_account(scopes):
"""Get an authenticated http object via a service account.
Args:
scopes: A string or a list of strings, the scopes to get credentials for.
Returns:
A pair or (credentials, http) objects, where 'http' is an authenticated
http client object, from which you can use the Google APIs.
"""
credentials = service_account.ServiceAccountCredentials.from_json_keyfile_name(
SERVICE_ACCOUNT_FILE, scopes)
http = httplib2.Http()
credentials.authorize(http)
return credentials, http