-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwr_google_docs.py
More file actions
50 lines (40 loc) · 1.42 KB
/
Copy pathwr_google_docs.py
File metadata and controls
50 lines (40 loc) · 1.42 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
from pprint import pprint
import re
import httplib2
import apiclient.discovery
from oauth2client.service_account import ServiceAccountCredentials
CREDENTIALS_FILE = 'file.json'
spreadsheet_id = 'enter yours'
credentials = ServiceAccountCredentials.from_json_keyfile_name(
CREDENTIALS_FILE,
['https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive'])
httpAuth = credentials.authorize(httplib2.Http())
service = apiclient.discovery.build('sheets', 'v4', http = httpAuth)
with open('file.data', 'r') as f:
nums = f.read().splitlines()
number_of_ct=len(nums)
number_of_ct -= 1
#number_of_ct=4
print("Containers on server:", number_of_ct)
i = 1
while number_of_ct > 0:
ct_info = re.split(r'[|]', nums[number_of_ct])
ia = str(i)
iA = "A"
gg = str(20)
gG = ":G"
range = (iA + ia + gG + gg)
values = service.spreadsheets().values().batchUpdate(
spreadsheetId=spreadsheet_id,
body={
"valueInputOption": "USER_ENTERED",
"data": [
{"range": range,
"majorDimension": "ROWS",
"values": [[ct_info[1], ct_info[2], ct_info[3], ct_info[4], ct_info[5], ct_info[6], ct_info[7]]]}
]
}
).execute()
i += 1
number_of_ct -= 1