-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReadAcsCldConfig.py
125 lines (106 loc) · 3.58 KB
/
ReadAcsCldConfig.py
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
'''
__author__ = "Ehtesham Hasnain"
__version__ = "1.0"
__email__ = "e.hasnain@esri.de"
Based upon EsriDE-python-osm2arcgis by Simon Geigenberger
'''
import sys
import json
def readAcsCldConfig():
url = "https://www.accessibility.cloud/place-infos"
accept = "application/json"
headers = {}
params = {}
filters = ["at-least-partially-accessible-by-wheelchair", "fully-accessible-by-wheelchair", "not-accessible-by-wheelchair", "unknown-wheelchair-accessibility"]
dictAcsCldConfig = {}
# Try to open the config file
try:
json_data = open("acscldconfig.json").read()
except:
print("JSON file does not exist.")
sys.exit()
# Try to load the config file as JSON, validate the JSON syntax
try:
data = json.loads(json_data)
except:
print("JSON file cannot be read.")
sys.exit()
#Validates if App-Token is provided
try:
AppToken = data["X-App-Token"]
headers["X-App-Token"] = AppToken
headers["Accept"] = accept
except:
print("Accessibility cloud app-token not provided")
sys.exit()
# Validates if parameters (latitude, longitude, radius, limit, filters) are provided
try:
parameters = data["requestparameters"]
try:
latitude = parameters["latitude"]
latitude = float(latitude)
params["latitude"] = latitude
except:
print("No latitude provided")
sys.exit()
try:
longitude = parameters["longitude"]
longitude = float(longitude)
params["longitude"] = longitude
except:
print("No longitude provided")
sys.exit()
try:
accuracy = parameters["radius"]
accuracy = float(accuracy)
params["accuracy"] = accuracy
except:
print("search radius not provided")
try:
limit = parameters["limit"]
limit = float(limit)
params["limit"] = limit
except:
print("Search limit not provided")
try:
searchfilter = parameters["filter"]
for items in filters:
filterExists = False
if items == searchfilter:
filterExists = True
break
if not filterExists:
print("Invalid accessibility search filter")
sys.exit()
params["filter"] = searchfilter
except SystemExit:
sys.exit()
except:
print("No accessibility filters chosen")
#Validation of the coordinates
if latitude < 90 and latitude > -90:
if longitude < 180 and longitude > -180:
print("Coordinates ok")
else:
print("Longitude is out of range.")
sys.exit()
else:
print("Latitude is out of range.")
sys.exit()
#Validation of the search radius
if accuracy < 10001 and accuracy > 0:
print("Search radius ok")
else:
print("Invalid search radius (valid 0 to 10000)")
sys.exit()
except SystemExit:
sys.exit()
except:
print("Location parameters not provided")
sys.exit()
dictAcsCldConfig["url"] = url
dictAcsCldConfig["headers"] = headers
dictAcsCldConfig["params"] = params
return(dictAcsCldConfig)
#test = readAcsCldConfig()
#print(test)