PK!gcsv/__init__.pyPK!K, gcsv/gcsv.pyimport pickle import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request class GCSV: def __init__(self, csv_filepath): self.csv = csv_filepath self.service = self.get_service() def get_service(self): # If modifying these scopes, delete the file "token.pickle". SCOPES = ['https://www.googleapis.com/auth/spreadsheets'] creds = None # The file token.pickle stores the user's access and refresh tokens, # and is created automatically when the authorization flow completes # for the first time. if os.path.exists('token.pickle'): with open('token.pickle', 'rb') as token: creds = pickle.load(token) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: creds.refresh(Request()) else: flow = InstalledAppFlow.from_client_secrets_file( 'credentials.json', SCOPES) creds = flow.run_local_server() # Save the credentials for the next run with open('token.pickle', 'wb') as token: pickle.dump(creds, token) service = build('sheets', 'v4', credentials=creds) return service def paste_to(self, spreadsheet_id, worksheet_gid, paste_start_row, paste_start_col): """ :param spreadsheet_id: The ID (or "key") of the spreadsheet; can be found in the spreadsheet URL after the "/d/" but before "/edit" :param worksheet_gid: The GID of the worksheet; can be found at the end of a Google sheets URL :param paste_start_row: The starting row of the paste destination (index starts at 1) :param paste_start_col: The starting column of the paste destination (index starts at 1) :return: The request response. """ with open(self.csv, 'r') as f: csv_data = f.read() request_body = { "requests": [{ "pasteData": { "coordinate": { "sheetId": worksheet_gid, "rowIndex": paste_start_row - 1, "columnIndex": paste_start_col - 1, }, "data": csv_data, "type": "PASTE_NORMAL", "delimiter": ",", } }] } request = self.service.spreadsheets().batchUpdate( spreadsheetId=spreadsheet_id, body=request_body ) response = request.execute() return response def clear_range(self, spreadsheet_id, spreadsheet_range): """ :param spreadsheet_id: The ID (or "key") of a spreadsheet; can be found in the spreadsheet URL after the "/d/" but before "/edit" :param range: The range in A1 notation for cells to be cleared :return: The request response. """ request_body = {} request = self.service.spreadsheets().values().clear( spreadsheetId=spreadsheet_id, range=spreadsheet_range, body=request_body ) response = request.execute() return response PK!=\@@gcsv-0.1.0.dist-info/LICENSEMIT License Copyright (c) 2019 Liam Corbett Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.PK!HڽTUgcsv-0.1.0.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!Hgcsv-0.1.0.dist-info/METADATATQO0~8VjB2* Q`/H\S$lӖ2`b~h}w}w: '{4V2#~Ⱦcv>?}6B:֠u@-a4тSpT#LWrMiQ̕sƽ^&ݪZD\be9 Ʒr+ebl A]tJΆ~==&\X+(D81km~Oǯ FeFk"ʬ"޿O^_HH P$t\b}6<~# ys8>A/DEEw7nP++2us@I4RBZS>sdclk(I, Le ΕH-(̏ wYoqisiho1o"7L!,AUZZw ϵ[@9c#"kh7XBOA@V`P".)]3DI0rL b#S3b1­8^ZU&6\GTه&;0V$3n/M {~Ij^;[fN[oWo%q٩aPK!HU8"gcsv-0.1.0.dist-info/RECORDm̽n@rCS$E_OĤ7~Yҏ3JYn |`}8oCN㍔{:#{.O t"gպRpqTqC$˃bqY./oܪ+ .l e(K4-곱*mB֢1~:!cyuCkV6q%io%A7NE|ES|u^'l&߆{K}t4XZ"x`H|DݹPK!gcsv/__init__.pyPK!K, .gcsv/gcsv.pyPK!=\@@#gcsv-0.1.0.dist-info/LICENSEPK!HڽTUgcsv-0.1.0.dist-info/WHEELPK!H)gcsv-0.1.0.dist-info/METADATAPK!HU8"Mgcsv-0.1.0.dist-info/RECORDPK