Spaces:
Sleeping
Sleeping
Update MC_Templates_API.py
Browse files- MC_Templates_API.py +53 -38
MC_Templates_API.py
CHANGED
|
@@ -1,61 +1,76 @@
|
|
| 1 |
import requests
|
| 2 |
import json
|
| 3 |
import pandas as pd
|
| 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 |
def APIValues():
|
| 36 |
-
query={"loginname":"
|
| 37 |
#token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiQURSIiwibmJmIjoiMTY4MDg1OTgzMyIsImV4cCI6IjE2ODA5MDMwMzMifQ.-FULhKD_M-cyIdSMMIYDlEo9DoZtc00yIlyXIPuyLZI"
|
| 38 |
head={'Content-Type':'application/json'}
|
| 39 |
url = "https://httpbin.org/post"
|
| 40 |
|
| 41 |
-
response=requests.post(url="https://
|
| 42 |
key=response.text #token generated
|
| 43 |
|
| 44 |
head={'Content-Type':'application/json;charset=UTF-8',"Authorization":'Bearer {}'.format(key)}
|
| 45 |
data={"pagesize": 1000000000}
|
| 46 |
-
response=requests.post(url=" https://
|
| 47 |
dict1=response.json()
|
| 48 |
return dict1
|
| 49 |
|
| 50 |
|
| 51 |
def RetrieveMC_Templates_API():
|
| 52 |
# threading.Timer(600.0,update_df).start()
|
| 53 |
-
|
| 54 |
dict1=APIValues()
|
| 55 |
for item in dict1.get('data') :
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
if
|
| 59 |
-
|
|
|
|
| 60 |
# print(json.dumps(DictionaryOfTemplates, indent=4))
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import requests
|
| 2 |
import json
|
| 3 |
import pandas as pd
|
| 4 |
+
import API
|
| 5 |
+
import numpy as np
|
| 6 |
+
mcDictionaryurl='https://docs.google.com/spreadsheets/d/1I4P7wiCXTAwnld0YQfUJC8bPtuiETna1HGWVuHbuDBk/edit#gid=1080620551'
|
| 7 |
+
def createDictionary():
|
| 8 |
+
DictionaryOfTemplates={
|
| 9 |
+
'1.0 substructure': [],
|
| 10 |
+
'2.1 frames' : [],
|
| 11 |
+
'2.2 upper floor':[],
|
| 12 |
+
'2.3 roof':[],
|
| 13 |
+
'2.4 stairs':[],
|
| 14 |
+
'2.5 external walls':[],
|
| 15 |
+
'2.6 external openings':[],
|
| 16 |
+
'2.7 internal walls':[],
|
| 17 |
+
'2.8 internal openings':[],
|
| 18 |
+
'3.1 wall finishes':[],
|
| 19 |
+
'3.2 floor finishes':[],
|
| 20 |
+
'3.3 ceiling finishes':[],
|
| 21 |
+
'4.0 fittings, furnishings and equipments':[],
|
| 22 |
+
'5.0 services':[],
|
| 23 |
+
'5.1 sanitary':[],
|
| 24 |
+
'7.0 works to existing buildings':[],
|
| 25 |
+
'8.1 site preparation works':[],
|
| 26 |
+
'8.2 roads, paths, pavings':[],
|
| 27 |
+
'8.3 soft landscaping':[],
|
| 28 |
+
'8.4 fencing, railing, walls':[],
|
| 29 |
+
'8.5 external fixtures':[],
|
| 30 |
+
'8.6 external drainage':[],
|
| 31 |
+
'8.7 external services':[],
|
| 32 |
+
'8.8 minor buildings':[]
|
| 33 |
+
}
|
| 34 |
+
return DictionaryOfTemplates
|
| 35 |
|
| 36 |
|
| 37 |
def APIValues():
|
| 38 |
+
query={"loginname":"Marthe","password":"marthemain"}
|
| 39 |
#token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiQURSIiwibmJmIjoiMTY4MDg1OTgzMyIsImV4cCI6IjE2ODA5MDMwMzMifQ.-FULhKD_M-cyIdSMMIYDlEo9DoZtc00yIlyXIPuyLZI"
|
| 40 |
head={'Content-Type':'application/json'}
|
| 41 |
url = "https://httpbin.org/post"
|
| 42 |
|
| 43 |
+
response=requests.post(url="https://console.trevorsadd.co.uk/account/login",json=query,headers=head)
|
| 44 |
key=response.text #token generated
|
| 45 |
|
| 46 |
head={'Content-Type':'application/json;charset=UTF-8',"Authorization":'Bearer {}'.format(key)}
|
| 47 |
data={"pagesize": 1000000000}
|
| 48 |
+
response=requests.post(url=" https://console.trevorsadd.co.uk/template/getgridview?isarchive=false",json=data,headers=head)
|
| 49 |
dict1=response.json()
|
| 50 |
return dict1
|
| 51 |
|
| 52 |
|
| 53 |
def RetrieveMC_Templates_API():
|
| 54 |
# threading.Timer(600.0,update_df).start()
|
| 55 |
+
DictionaryOfTemplates=createDictionary()
|
| 56 |
dict1=APIValues()
|
| 57 |
for item in dict1.get('data') :
|
| 58 |
+
if item.get('section'):
|
| 59 |
+
section=item.get('section').lower()
|
| 60 |
+
if section in DictionaryOfTemplates.keys():
|
| 61 |
+
if item.get('templatename') not in DictionaryOfTemplates[section]:
|
| 62 |
+
DictionaryOfTemplates[section].append([item.get('templatename'),item.get('unit')])
|
| 63 |
# print(json.dumps(DictionaryOfTemplates, indent=4))
|
| 64 |
+
# mctoSheets( DictionaryOfTemplates)
|
| 65 |
+
return DictionaryOfTemplates
|
| 66 |
+
|
| 67 |
+
def mctoSheets( DictionaryOfTemplates):
|
| 68 |
+
gc=API.AuthorizeGoogleSheets()[2]
|
| 69 |
+
ws = gc.open_by_key('1I4P7wiCXTAwnld0YQfUJC8bPtuiETna1HGWVuHbuDBk')
|
| 70 |
+
|
| 71 |
+
MC_TNamesSheet=ws.worksheet_by_title('MC-T Names')
|
| 72 |
+
MC_TNamesSheet.clear()
|
| 73 |
+
# MC_DF=pd.DataFrame( DictionaryOfTemplates.items())
|
| 74 |
+
MC_DF=pd.DataFrame({k: np.ravel(v) for k, v in DictionaryOfTemplates.items()})
|
| 75 |
+
#append tables to google sheets
|
| 76 |
+
MC_TNamesSheet.set_dataframe(start='A1',df=MC_DF)
|