Marthee commited on
Commit
d3083bf
·
1 Parent(s): 9e88c52

Upload 2 files

Browse files
Files changed (2) hide show
  1. Dropbox_TSA_API.py +43 -0
  2. MC_Templates_API.py +61 -0
Dropbox_TSA_API.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """Dropbox_new_API(ALAA).ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/19yoasKJcLTUJ3EfLv40J26YHSi7tjEPZ
8
+ """
9
+
10
+ import base64
11
+ import requests
12
+ import json
13
+ import pathlib
14
+ import pandas as pd
15
+ import dropbox
16
+ from dropbox.exceptions import AuthError
17
+ import fitz
18
+
19
+ """### NEW CODE - OCTOBER 26 - Marthe"""
20
+
21
+ app_key='9bljerefjumct38'
22
+ app_secret='nl6k66clw1j1k12'
23
+ access_code='sl.Bou05Rb15xPy851-I1UV8oOabHPY21AEPl5nrYl-Q0ninFSy0kTuRWPSve_JPbd3Z03E7eBY4r9R454rdzDM0AxLkyqrQEDzyAGUwP7kZ7s2CR6EwvdLD2a7Xh8nFEs38voLTH2IHzrQ2QEx7rji4OJ8aSQStKtJkI7_dh8tYHj5'
24
+ refresh_token='qK2VqvbxWMMAAAAAAAAAAXFQvrHM4xUwWUcZ6l5vGOygn1iAA6zlDjmAQNBbZprL'
25
+ basic_auth=base64.b64encode(f'{app_key}:{app_secret}'.encode())
26
+
27
+ def ADR_Access_DropboxTeam():
28
+ dbx = dropbox.DropboxTeam(app_key=app_key,
29
+ app_secret=app_secret,
30
+ oauth2_refresh_token = refresh_token).as_user('dbmid:AACjJg2GKc3tI42iOnD01dd6s0XDyyx6Thw')
31
+ root_namespace_id = dbx.users_get_current_account().root_info.root_namespace_id
32
+ dbx = dbx.with_path_root(dropbox.common.PathRoot.root(root_namespace_id))
33
+ return dbx
34
+ #_____________________________________________________________________________________________________________________________
35
+ #_____________________________________________________________________________________________________________________________
36
+ def getSharedLink(path):
37
+ dbx=ADR_Access_DropboxTeam()
38
+ try:
39
+ shared_link_metadata = dbx.sharing_create_shared_link_with_settings(path)
40
+ except:
41
+ shared_link_metadata=dbx.sharing_create_shared_link(path)
42
+ print(shared_link_metadata.url)
43
+ return shared_link_metadata.url
MC_Templates_API.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import json
3
+ import pandas as pd
4
+
5
+
6
+ DictionaryOfTemplates={
7
+ '1.0 substructure': [],
8
+ '2.1 frames' : [],
9
+ '2.2 upper floor':[],
10
+ '2.3 roof':[],
11
+ '2.4 stairs':[],
12
+ '2.5 external walls':[],
13
+ '2.6 external openings':[],
14
+ '2.7 internal walls':[],
15
+ '2.8 internal openings':[],
16
+ '3.1 wall finishes':[],
17
+ '3.2 floor finishes':[],
18
+ '3.3 ceiling finishes':[],
19
+ '4.0 fittings, furnishings and equipments':[],
20
+ '5.0 services':[],
21
+ '5.1 sanitary':[],
22
+ '7.0 works to existing buildings':[],
23
+ '8.1 site preparation works':[],
24
+ '8.2 roads, paths, pavings':[],
25
+ '8.3 soft landscaping':[],
26
+ '8.4 fencing, railing, walls':[],
27
+ '8.5 external fixtures':[],
28
+ '8.6 external drainage':[],
29
+ '8.7 external services':[],
30
+ '8.8 minor buildings':[]
31
+ }
32
+
33
+
34
+
35
+ def APIValues():
36
+ query={"loginname":"adr","password":"Tameen"}
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://consoletest.trevorsadd.co.uk/account/login",json=query,headers=head)
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://consoletest.trevorsadd.co.uk/template/getgridview?isarchive=false",json=data,headers=head)
47
+ dict1=response.json()
48
+ return dict1
49
+
50
+
51
+ def RetrieveMC_Templates_API():
52
+ # threading.Timer(600.0,update_df).start()
53
+ global DictionaryOfTemplates
54
+ dict1=APIValues()
55
+ for item in dict1.get('data') :
56
+ section=item.get('section').lower()
57
+ if section in DictionaryOfTemplates.keys():
58
+ if item.get('templatename') not in DictionaryOfTemplates[section]:
59
+ DictionaryOfTemplates[section].append([item.get('templatename'),item.get('unit')])
60
+ # print(json.dumps(DictionaryOfTemplates, indent=4))
61
+ return DictionaryOfTemplates