Exemple #1
0
 def push_to_google_sheet(self, data_frame, sheet_id):
     '''
         Pushing the Data Frame to a google sheet worksheet.
     '''
     #TODO:
     # 1. If an older backup sheet exists delete it
     # 2. Generate a timestamp --> figure out where to add it
     # 3. Write to a new sheet.
     ServiceAccountCredentials.from_json()
Exemple #2
0
 def __init__(self, st_obj, secret):
     self.st_obj = st_obj
     # use creds to create a client to interact with the Google Drive API
     self.scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
     #secret = 'client_secret.json'
     self.creds = ServiceAccountCredentials.from_json(secret)
     #self.creds = ServiceAccountCredentials.from_json_keyfile_name(secret, self.scope)
     self.client = gspread.authorize(self.creds)
Exemple #3
0
def get_worksheet():
    s3 = boto3.resource('s3')
    obj = s3.Bucket(BUCKET).Object(CREDS_FILE)
    scope = [GSHEET_SCOPE]
    credentials = ServiceAccountCredentials.from_json(obj.get()['Body'].read())
    credentials_with_scope = credentials.create_scoped(scope)
    gc = gspread.authorize(credentials_with_scope)
    wks = gc.open(SHEET_NAME).sheet1
    return wks
Exemple #4
0
def getGoogleAccess():
    keys = {"access_token": None, "client_id": "108396352402276263785", "client_secret": None, "refresh_token": None,
            "token_expiry": None, "token_uri": "https://accounts.google.com/o/oauth2/token", "user_agent": None,
            "revoke_uri": "https://oauth2.googleapis.com/revoke", "id_token": None, "id_token_jwt": None,
            "token_response": None, "scopes": [], "token_info_uri": None, "invalid": False, "assertion_type": None,
            "_service_account_email": "*****@*****.**",
            "_scopes": "https://spreadsheets.google.com/feeds https://www.googleapis.com/auth/drive",
            "_private_key_id": os.environ['GOOGLE_PRIVATE_KEY_ID'], "_user_agent": None, "_kwargs": {},
            "_private_key_pkcs8_pem": os.environ['GOOGLE_PRIVATE_KEY'].replace('\\n', '\n'),
            "_class": "ServiceAccountCredentials", "_module": "oauth2client.service_account"}
    credentials = ServiceAccountCredentials.from_json(keys)
    return gspread.authorize(credentials)
Exemple #5
0
# Create your views here.
from django.http import HttpResponse
import sendgrid
import os, random
from sendgrid.helpers.mail import *
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import datetime

key = '{"access_token": null, "client_id": "104741969451609727742", "client_secret": null, "refresh_token": null, "token_expiry": null, "token_uri": "https://oauth2.googleapis.com/token", "user_agent": null, "revoke_uri": "https://accounts.google.com/o/oauth2/revoke", "id_token": null, "token_response": null, "scopes": [], "token_info_uri": null, "invalid": false, "assertion_type": null, "_service_account_email": "*****@*****.**", "_scopes": "https://spreadsheets.google.com/feeds https://www.googleapis.com/auth/drive", "_private_key_id": "fa27c6f09d8be19df4e72a9e5a740a7b248b8ecc", "_user_agent": null, "_kwargs": {}, "_private_key_pkcs8_pem": "-----BEGIN PRIVATE KEY-----\\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC4XbGXXZaw6S5G\\neDo9vw+h6XY4AmIBqF4N5nVdAQ8Qm0v/WHVTrJBOZkkJRK7wOmpfkwV2it5/7jVe\\nfPLGONAQ7T+uxlv7BBSyj0qi2w8Gwl6KFqZuEaG8uoIKIZUoZEOEfBbvpfy57GlW\\nglpoRG8FIxh3Lv0gIqiYTCu/e5XHCkFOZ3nSgRMRJMWbPkiL+Rq/mFlpou5R+VYG\\nFxyGOSd3fnVgefL53RvW2hbZWLnh/KQ12jVTuf/0XKE5tKRAw2uXohxDELVKIpU2\\nVnB07LWcSPE1K3UJuNiCfzgU8RshMROuZxvpfdl1SB7edl9Mc+qNkTWr4WgBUWcK\\npen8oxAZAgMBAAECggEAELIFXsJuHrujAeUpywUmBoDEgJpwoxtK1yHnP2KU6WlS\\nxr8NMuRV1g+rrf/vApiboOeIr10wfG/HG/UfLAWhi+LcKTjTxAWw1SGmPdyt/ev0\\nkTcvX5jPp25RT9cOMY/w0ErHbfC/U9vdhyS7SKVn01SEBuj1qacR0ubU8Fxh6hnz\\nHHhvYBAT12BR/Yc1+JhayTtBXVES4gJNleAEJ88n2ZNzV4ltG6i6vKzF55u+oLrD\\nmPxUujbnfVQiWa/ZtApmHD4j7isC7rrokFAf8W6njSMbzA1aYt3dcgI62qh2lRPp\\nBI/XDHqIchvBOLRkwRAtluar9Z+0OFvMdo7AUXaafQKBgQD72U0odGv7gjH36FPH\\n04SsHDAftb74CoT1YiI+XO1uXYBq6dVgVQd0gawvKvaWx9xK3GVgsPn2w5kka5KN\\nIMJduju+yZe5fGjxARYHSPQV3mMqFf6JvpasbiVqqHyIdWCSQIqjqp74YsW7xDeg\\n1flfS675r3OQ2TK0cmtUj2JLjQKBgQC7Z6R3f+cij1yvnkRSgkinjV+uLUx7b4fO\\nXABtSFRPnSI5e2MTYP/z5yD1+ZsOK+nrTKBmOlARdmam0P43hlFYShzdd3Kd4vn0\\neWBdBs42IgJAEUpBDHfLREchbLNTOjo/sQIXEYrM0F+ghNFdP1fjejUwv0mwSee6\\nkfcEUc+tvQKBgQDRCSAdv+QQsZO/7Ln9Vfb807it2TBUuIZ7FaTOllsMC9eW5dcR\\nSgISFb9QtxxNMj4KdLxAcSRISTlHHXJaaSJqoTUNuk2Qy05fG0OpcEgIDrnIKNFI\\ni0SMgi/UQ1x59tLdEW0BQ5EHIRR2MPrrKC7/hdYJsDL/uwd29rFXUluH0QKBgBl9\\nZV9jpDqNKVwxuLVIRz2S+xqjyq1XZC9rUBuNJPqXMtqCr90o6mdwXolWZAKvcmew\\nynhdIhrd8eRqtMk0mcfafMaawpo7DyhzgenlTRML2SaBs4nZeknJhatEL7f4SYf0\\nOYaNukVVakxZBGkcfoXQT3/L5Of3hW9Y/zI1Nnw5AoGAPa+1Qv2nP3caFh8P/aQC\\nl5GlKjxnFidguqLSnfNdLY0tOzziMMAlLGebz+ONskJNR1idJHV6A9tOVR3H/d3k\\nHE55kug0qr4DxEKOlQsuuL+2GuccQwdLzOOWquyiBwBMPph56Xh4hFJdocO8Lkh7\\n/qIp7iwHeh2xIg4+lJFNg2A=\\n-----END PRIVATE KEY-----\\n", "_class": "ServiceAccountCredentials", "_module": "oauth2client.service_account"}'
scope = [
    'https://spreadsheets.google.com/feeds',
    'https://www.googleapis.com/auth/drive'
]
creds = ServiceAccountCredentials.from_json(key)
client = gspread.authorize(creds)
sheet = client.open('entries').sheet1


def index(request):
    global scope, creds, client, sheet, key
    context = {}
    if (request.method == 'GET'):

        r_otp = request.GET.get('otp')
        sender = Email(request.GET.get('sender'))

        r_mail = request.GET.get('reciever')
        reciever = Email(request.GET.get('reciever'))
        subject = request.GET.get('subject')