-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsheets.py
More file actions
127 lines (105 loc) · 4.6 KB
/
sheets.py
File metadata and controls
127 lines (105 loc) · 4.6 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from pprint import pprint
from googleapiclient.discovery import build
from google.oauth2.credentials import Credentials
from googleapiclient.http import MediaIoBaseUpload
from datetime import datetime
import os.path
from io import BytesIO
import sys
from base64 import urlsafe_b64encode
from email.mime.text import MIMEText
credentials = {
######################"<Your project's service account credentials here>"##################################
}
scope = ["https://spreadsheets.google.com/feeds", 'https://www.googleapis.com/auth/spreadsheets',
"https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive",
]
creds = ServiceAccountCredentials.from_json_keyfile_dict(credentials,scope)
client = gspread.authorize(creds)
try:
sheet = client.open("SHEET YOU WANT TO ACCESS").sheet1
except:
sheet = client.open("SHEET YOU WANT TO ACCESS").sheet1
def loginverify(username,password):
try:
userid=[]
usernameslist = sheet.col_values(2)
k=0;
#cell = sheet.cell(4, 1).value
for i in usernameslist :
k=k+1
if username == i:
userid = [sheet.cell(k, 2).value, sheet.cell(k, 3).value]
break
if userid[0]!=username :
return (0, 0, 0)
if userid[1]==password:
return (1, getDetails(username, k), k)
else :
return (0, 0, 0)
except:
return (0,0,0)
def SUBMITDATA(username, exp, data, k):
try:
EXP = client.open("LOP Database")
temp = EXP.get_worksheet(exp)
if(temp.cell(k, 2).value == username):
flag = 0
for i in data:
temp.update_cell(k, 3+flag, str(i))
flag+=1
return 1
else:
return 0
except:
return 0
def getDetails(username, k):
try:
if(sheet.cell(k, 2).value == username):
userid = sheet.row_values(k)
return userid
return None
except:
return None
def fetchDetails(username):
try:
usernameslist = sheet.col_values(2)
k=0
for i in usernameslist :
k=k+1
if username == i:
#print("in here")
userid = [sheet.cell(k, 2).value, sheet.cell(k, 3).value]
return userid
return None
except:
return None
def UPLOADONDRIVE2(DATA_Misc, dataGEN, dataIN, labels, folder_id="1FJDYxVhN3e5_bs2TFC9VlUzS3S3JuXhU"):
try:
service = build('drive', 'v3', credentials=creds, static_discovery=False)
stringdata = str(DATA_Misc[0])+"\n\n"+str(DATA_Misc[2])+"\n"+str(DATA_Misc[1])
stringdata = stringdata + "\n\n-----:GENERATED:-----\n"
flag = 0
for i in dataGEN:
stringdata = stringdata+str(labels[flag])+"->"+str(i)+"\n"
flag+=1
flag = 0
stringdata = stringdata + "\n\n-----:USER INPUT:-----\n"
for i in dataIN:
stringdata = stringdata+str(labels[flag])+"->"+str(i)+"\n"
flag+=1
bio = BytesIO(stringdata.encode())
#print(bio)
file_meta = {"name": str(str(DATA_Misc[0])+"_"+str(DATA_Misc[1])+".txt"),
"parents": [folder_id]}
media = MediaIoBaseUpload(bio, mimetype='text/plain',
resumable=True)
#file3 = file1.get('id')
request = service.files().create(body=file_meta, media_body=media,
fields = 'id').execute()
#print("Upload Complete")
return 1
except:
return 0