forked from felixhalim/python-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_reg_user.py
34 lines (27 loc) · 1.31 KB
/
update_reg_user.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
import gspread
from oauth2client.service_account import ServiceAccountCredentials
import pprint
scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']
creds = ServiceAccountCredentials.from_json_keyfile_name('spreadsheet-token.json', scope)
client = gspread.authorize(creds)
registered_user = client.open('Project_Goodall').worksheet("Registered_User")
Dictionary={}
# Function to sync with data on spreadsheet
def getLatestData():
tele_id_list = registered_user.col_values(1)
matric_list = registered_user.col_values(2)
name_list = registered_user.col_values(3)
counter_help_list = registered_user.col_values(4)
bool_donate_list = registered_user.col_values(5)
index_list = registered_user.col_values(6)
value_list = list(map(list, zip(matric_list,name_list,counter_help_list,bool_donate_list,index_list)))
Dictionary.update(dict(zip(tele_id_list, value_list)))
return Dictionary
# Function to alter data on spreadsheet
def setData(telegram_id,index_dict,value):
if(index_dict=="bool_donate"):
index_dict=3
elif(index_dict=="counter_help"):
index_dict=2
row_dict = Dictionary[telegram_id][4] # 4 is the index in terms of row
registered_user.update_cell(int(row_dict)+2, int(index_dict)+2, value) # +2 offset based on spreadsheet