Spaces:
Sleeping
Sleeping
File size: 2,992 Bytes
d3083bf 377f0d7 d3083bf 377f0d7 d3083bf 12894ac d3083bf 12894ac d3083bf 377f0d7 d3083bf 377f0d7 d3083bf 377f0d7 12894ac 377f0d7 |
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 |
import requests
import json
import pandas as pd
import API
import numpy as np
mcDictionaryurl='https://docs.google.com/spreadsheets/d/1I4P7wiCXTAwnld0YQfUJC8bPtuiETna1HGWVuHbuDBk/edit#gid=1080620551'
def createDictionary():
DictionaryOfTemplates={
'1.0 substructure': [],
'2.1 frames' : [],
'2.2 upper floor':[],
'2.3 roof':[],
'2.4 stairs':[],
'2.5 external walls':[],
'2.6 external openings':[],
'2.7 internal walls':[],
'2.8 internal openings':[],
'3.1 wall finishes':[],
'3.2 floor finishes':[],
'3.3 ceiling finishes':[],
'4.0 fittings, furnishings and equipments':[],
'5.0 services':[],
'5.1 sanitary':[],
'7.0 works to existing buildings':[],
'8.1 site preparation works':[],
'8.2 roads, paths, pavings':[],
'8.3 soft landscaping':[],
'8.4 fencing, railing, walls':[],
'8.5 external fixtures':[],
'8.6 external drainage':[],
'8.7 external services':[],
'8.8 minor buildings':[]
}
return DictionaryOfTemplates
def APIValues():
query={"loginname":"Marthe","password":"marthemain"}
#token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiQURSIiwibmJmIjoiMTY4MDg1OTgzMyIsImV4cCI6IjE2ODA5MDMwMzMifQ.-FULhKD_M-cyIdSMMIYDlEo9DoZtc00yIlyXIPuyLZI"
head={'Content-Type':'application/json'}
url = "https://httpbin.org/post"
response=requests.post(url="https://console.trevorsadd.co.uk/account/login",json=query,headers=head,verify=False)
key=response.text #token generated
head={'Content-Type':'application/json;charset=UTF-8',"Authorization":'Bearer {}'.format(key)}
data={"pagesize": 1000000000}
response=requests.post(url=" https://consoletest.trevorsadd.co.uk/template/getgridview?isarchive=false",json=data,headers=head,verify=False)
dict1=response.json()
return dict1
def RetrieveMC_Templates_API():
# threading.Timer(600.0,update_df).start()
DictionaryOfTemplates=createDictionary()
dict1=APIValues()
for item in dict1.get('data') :
if item.get('section'):
section=item.get('section').lower()
if section in DictionaryOfTemplates.keys():
if item.get('templatename') not in DictionaryOfTemplates[section]:
DictionaryOfTemplates[section].append([item.get('templatename'),item.get('unit')])
# print(json.dumps(DictionaryOfTemplates, indent=4))
# mctoSheets( DictionaryOfTemplates)
# print(DictionaryOfTemplates)
return DictionaryOfTemplates
def mctoSheets( DictionaryOfTemplates):
gc=API.AuthorizeGoogleSheets()[2]
ws = gc.open_by_key('1I4P7wiCXTAwnld0YQfUJC8bPtuiETna1HGWVuHbuDBk')
MC_TNamesSheet=ws.worksheet_by_title('MC-T Names')
MC_TNamesSheet.clear()
# MC_DF=pd.DataFrame( DictionaryOfTemplates.items())
MC_DF=pd.DataFrame({k: np.ravel(v) for k, v in DictionaryOfTemplates.items()})
#append tables to google sheets
MC_TNamesSheet.set_dataframe(start='A1',df=MC_DF)
|