-
Notifications
You must be signed in to change notification settings - Fork 6
/
__main__.py
43 lines (28 loc) · 1.35 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import httplib2
from googleapiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
import creds
def get_service_simple():
return build('sheets', 'v4', developerKey=creds.api_key)
def get_service_sacc():
"""
Могу читать и (возможно) писать в таблицы кот. выдан доступ
для сервисного аккаунта приложения
:return:
"""
creds_json = os.path.dirname(__file__) + "/creds/sacc1.json"
scopes = ['https://www.googleapis.com/auth/spreadsheets']
creds_service = ServiceAccountCredentials.from_json_keyfile_name(creds_json, scopes).authorize(httplib2.Http())
return build('sheets', 'v4', http=creds_service)
# service = get_service_simple()
service = get_service_sacc()
sheet = service.spreadsheets()
# https://docs.google.com/spreadsheets/d/xxx/edit#gid=0
sheet_id = "xxx"
# https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get
# resp = sheet.values().get(spreadsheetId=sheet_id, range="Лист1!A1:A999").execute()
# https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/batchGet
resp = sheet.values().batchGet(spreadsheetId=sheet_id, ranges=["Лист1", "Лист2"]).execute()
print(resp)