-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsheetsTest.py
More file actions
73 lines (61 loc) · 2.05 KB
/
sheetsTest.py
File metadata and controls
73 lines (61 loc) · 2.05 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import pickle
import os.path
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
from googleapiclient.discovery import build
import pandas as pd
# okej te funkcije neki delajo
def pull_sheet_data(SCOPES,SPREADSHEET_ID,DATA_TO_PULL):
creds = gsheet_api_check(SCOPES)
service = build('sheets', 'v4', credentials=creds)
sheet = service.spreadsheets()
result = sheet.values().get(
spreadsheetId=SPREADSHEET_ID,
range=DATA_TO_PULL).execute()
values = result.get('values', [])
if not values:
print('No data found.')
else:
rows = sheet.values().get(spreadsheetId=SPREADSHEET_ID,
range=DATA_TO_PULL).execute()
data = rows.get('values')
print("COMPLETE: Data copied")
return data
def gsheet_api_check(SCOPES):
creds = None
if os.path.exists('token.pickle'):
with open('token.pickle', 'rb') as token:
creds = pickle.load(token)
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(port=0)
with open('token.pickle', 'wb') as token:
pickle.dump(creds, token)
return creds
# koda
SCOPES = ['https://www.googleapis.com/auth/spreadsheets']
SPREADSHEET_ID = '1Cv9EgP-gcNYhTOR2O9DxDBdSoSLT0iBg5lDCvBdx51E'
DATA_TO_PULL = 'tocke'
#dobimo vse podatke
data = pull_sheet_data(SCOPES,SPREADSHEET_ID,DATA_TO_PULL)
# vzamemo tocke ven
dataTocke = data[4:]
imena = ['igre', 'peter', 'nace', 'blaz', 'gasper', 'jernej', 'klancar']
tocke = []
stIger = 0
for line in dataTocke:
if line[1] == '':
break
stIger += 1
tocke.append(line[2:9])
# napisemo tocke v fajle z imeni
for i in range(7):
print(i, imena[i])
f = open(imena[i] + ".txt", "w")
for j in range(stIger):
f.write(tocke[j][i] + "\n")
f.close()