Spaces:
Sleeping
Sleeping
Update API.py
Browse files
API.py
CHANGED
|
@@ -8,9 +8,7 @@
|
|
| 8 |
import requests
|
| 9 |
import json
|
| 10 |
import pandas as pd
|
| 11 |
-
|
| 12 |
-
# %% [markdown]
|
| 13 |
-
# ## GoogleSheet
|
| 14 |
|
| 15 |
# %%
|
| 16 |
# from __future__ import print_function
|
|
@@ -18,6 +16,7 @@ from googleapiclient.discovery import build
|
|
| 18 |
from google.oauth2 import service_account
|
| 19 |
import pygsheets
|
| 20 |
import numpy as np
|
|
|
|
| 21 |
|
| 22 |
prjnamesURL= 'https://docs.google.com/spreadsheets/d/1I4P7wiCXTAwnld0YQfUJC8bPtuiETna1HGWVuHbuDBk/edit#gid=0'
|
| 23 |
prjpartsURL= 'https://docs.google.com/spreadsheets/d/1I4P7wiCXTAwnld0YQfUJC8bPtuiETna1HGWVuHbuDBk/edit#gid=2102042200'
|
|
@@ -110,13 +109,10 @@ def GenerateTables():
|
|
| 110 |
table3= pd.concat([table3,pd.DataFrame([[item.get('id'),section.get('projectPartId'),section.get('section')]], columns=table3.columns)], ignore_index=True)
|
| 111 |
return table1,table2,table3
|
| 112 |
|
| 113 |
-
# %% [markdown]
|
| 114 |
# Set Tables to Sheets
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
def AppendtablestoSheets(ws):
|
| 119 |
-
|
| 120 |
table1,table2,table3= GenerateTables()
|
| 121 |
projectNamesSheet=ws.worksheet_by_title('Project Names')
|
| 122 |
projectPartsSheet=ws.worksheet_by_title('Project Parts')
|
|
@@ -169,28 +165,18 @@ def getprjSections(chosenprjname, chosenpart,urlSection=prjsectionsURL):
|
|
| 169 |
sections=dfSections['ProjectSection'].tolist()
|
| 170 |
return sections
|
| 171 |
|
| 172 |
-
# %%
|
| 173 |
-
# tableTrial=pd.DataFrame(data=[[0,'0x','part1'],[0,'1x','part2']],columns= ['ProjectId','ProjectPartId','ProjectPart'])
|
| 174 |
-
# tableTrial3=pd.DataFrame(data=[[0,'0x','0.0'],[0,'0x','1.0'],[1,'1x','3.1']],columns= ['ProjectId','ProjectPartId','ProjectSection'])
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
# %%
|
| 178 |
-
#Ex: proj 1 ekhtrnah fl dropdown-->go search in table where column of names has the name proj 1 , get id of this proj1 (same row and return it to this line)
|
| 179 |
-
#get parts
|
| 180 |
-
# partsList=list(tableTrial.loc[tableTrial['ProjectId'].isin([id])].get('ProjectPart'))
|
| 181 |
-
#get sections
|
| 182 |
-
# sectionsList=list(tableTrial3.loc[tableTrial3['ProjectId'].isin([projid]) & tableTrial3['projpartid'].isin(['0x'])].get('ProjectSection'))
|
| 183 |
-
# tableTrial3
|
| 184 |
-
|
| 185 |
-
# %%
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
|
| 190 |
##############################################################################
|
| 191 |
-
def update_df(
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
import requests
|
| 9 |
import json
|
| 10 |
import pandas as pd
|
| 11 |
+
import threading
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# %%
|
| 14 |
# from __future__ import print_function
|
|
|
|
| 16 |
from google.oauth2 import service_account
|
| 17 |
import pygsheets
|
| 18 |
import numpy as np
|
| 19 |
+
from datetime import datetime
|
| 20 |
|
| 21 |
prjnamesURL= 'https://docs.google.com/spreadsheets/d/1I4P7wiCXTAwnld0YQfUJC8bPtuiETna1HGWVuHbuDBk/edit#gid=0'
|
| 22 |
prjpartsURL= 'https://docs.google.com/spreadsheets/d/1I4P7wiCXTAwnld0YQfUJC8bPtuiETna1HGWVuHbuDBk/edit#gid=2102042200'
|
|
|
|
| 109 |
table3= pd.concat([table3,pd.DataFrame([[item.get('id'),section.get('projectPartId'),section.get('section')]], columns=table3.columns)], ignore_index=True)
|
| 110 |
return table1,table2,table3
|
| 111 |
|
|
|
|
| 112 |
# Set Tables to Sheets
|
| 113 |
+
def AppendtablestoSheets():
|
| 114 |
+
gc=AuthorizeGoogleSheets()[2]
|
| 115 |
+
ws = gc.open_by_key('1I4P7wiCXTAwnld0YQfUJC8bPtuiETna1HGWVuHbuDBk')
|
|
|
|
|
|
|
| 116 |
table1,table2,table3= GenerateTables()
|
| 117 |
projectNamesSheet=ws.worksheet_by_title('Project Names')
|
| 118 |
projectPartsSheet=ws.worksheet_by_title('Project Parts')
|
|
|
|
| 165 |
sections=dfSections['ProjectSection'].tolist()
|
| 166 |
return sections
|
| 167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
##############################################################################
|
| 170 |
+
def update_df(): #get file from drive
|
| 171 |
+
url_1 = prjnamesURL.replace('/edit#gid=', '/export?format=csv&gid=')
|
| 172 |
+
df_Old = pd.read_csv(url_1)
|
| 173 |
+
threading.Timer(20.0,update_df).start()
|
| 174 |
+
print(datetime.now())
|
| 175 |
+
|
| 176 |
+
df_New = pd.read_csv(url_1)
|
| 177 |
+
df_diff = pd.concat([df_Old,df_New]).drop_duplicates(keep=False)
|
| 178 |
+
print('kkkkkkkkkkkkkkkkkkkkk',df_diff)
|
| 179 |
+
# if df_diff.shape[0] >0:
|
| 180 |
+
# print('new')
|
| 181 |
+
# print(df_diff)
|
| 182 |
+
# AppendtablestoSheets()
|