Skip to content

Commit 990fc9c

Browse files
Fixes for MSE URL and API change
1 parent 92cb59e commit 990fc9c

File tree

9 files changed

+80
-80
lines changed

9 files changed

+80
-80
lines changed
Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
from urllib.request import Request, urlopen
22
import json
33

4-
uri = 'https://msesandbox.cisco.com/api/contextaware/v1/maps/info/DevNetCampus'
4+
uri = 'https://devnetapi.cisco.com/sandbox/mse/api/config/v1/maps/info/DevNetCampus'
5+
56

67
def get_content(uri):
7-
req = Request(uri)
8-
req.add_header('Authorization', 'Basic bGVhcm5pbmc6bGVhcm5pbmc==')
9-
req.add_header('Accept', 'application/json')
10-
response = urlopen(req)
11-
responseString = response.read().decode("utf-8")
12-
response.close()
13-
return responseString
8+
req = Request(uri)
9+
req.add_header('Authorization', 'Basic bGVhcm5pbmc6bGVhcm5pbmc=')
10+
req.add_header('Accept', 'application/json')
11+
response = urlopen(req)
12+
response_string = response.read().decode("utf-8")
13+
response.close()
14+
return response_string
15+
1416

15-
jsonObject = json.loads(get_content(uri))
17+
json_object = json.loads(get_content(uri))
1618

1719
building_names = []
1820

19-
buildings = jsonObject["Campus"]["Building"]
20-
for building in buildings:
21-
building_names.append(building["name"])
21+
buildings = json_object["buildingList"]
22+
for building in buildings:
23+
building_names.append(building["name"])
2224

25+
# Print out the building names found - this is a Python list
2326
print(building_names)
24-
for building_name in building_names:
25-
building_uri = uri + "/" + building_name
26-
print(building_uri)
27-
print(get_content(building_uri))
27+
28+
# Get the content for each of the buildings found by iterating through the building list
29+
for building_name in building_names:
30+
building_uri = uri + "/" + building_name
31+
print(building_uri)
32+
print(get_content(building_uri))
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
from urllib.request import Request, urlopen
22
import json
33

4-
req = Request('https://msesandbox.cisco.com/api/contextaware/v1/maps/info/DevNetCampus')
5-
req.add_header('Authorization', 'Basic bGVhcm5pbmc6bGVhcm5pbmc==')
6-
req.add_header('Accept', 'application/json')
4+
req = Request('https://devnetapi.cisco.com/sandbox/mse/api/config/v1/maps')
5+
req.add_header('Authorization', 'Basic bGVhcm5pbmc6bGVhcm5pbmc=')
76
response = urlopen(req)
8-
response_string = response.read().decode("utf-8")
7+
response_string = response.read().decode('utf-8')
98

109
json_object = json.loads(response_string)
1110

12-
print(json_object["Campus"]["Building"])
11+
print(json_object['campuses'])
1312

14-
#buildings = json_object["Campus"]["Building"]
15-
#for building in buildings:
16-
# print(building["name"])
13+
# campuses = json_object['campuses']
14+
# for campus in campuses:
15+
# print(campus['name'])
16+
# # for building in campus['buildingList']:
17+
# # print('\t' + building['name'])
1718

18-
response.close()
19+
response.close()
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
from urllib.request import Request, urlopen
22
import json
33

4-
req = Request('https://msesandbox.cisco.com/api/contextaware/v1/maps/info/DevNetCampus/DevNetBuilding')
5-
req.add_header('Authorization', 'Basic bGVhcm5pbmc6bGVhcm5pbmc==')
6-
req.add_header('Accept', 'application/json')
4+
req = Request('https://devnetapi.cisco.com/sandbox/mse/api/config/v1/maps/info/DevNetCampus/DevNetBuilding')
5+
req.add_header('Authorization', 'Basic bGVhcm5pbmc6bGVhcm5pbmc=')
76
response = urlopen(req)
8-
response_string = response.read().decode("utf-8")
7+
response_string = response.read().decode('utf-8')
98

109
json_object = json.loads(response_string)
1110

12-
print(json_object["Building"])
11+
print(json_object['floorList'])
1312

14-
#floors = json_object["Building"]["Floor"]
15-
#for floor in floors:
16-
# print("Floor Number: " + str(floor["floorNumber"]))
17-
# aps = floor["AccessPoint"]
18-
# for ap in aps:
19-
# print(" " + ap["name"] + "/" + ap["ipAddress"] + "/")
13+
# Parse out the floors from the result set
14+
# floors = json_object["floorList"]
15+
# for floor in floors:
16+
# print(floor['name'] + ' Floor Number: ' + str(floor['floorNumber']))
17+
# # Parse out the access points from the returned floors
18+
# # aps = floor["accessPoints"]
19+
# # for ap in aps:
20+
# # print('\t' + ap['name'] + '/' + ap['radioMacAddress'])
2021

2122
response.close()
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
from urllib.request import Request, urlopen
22
import json
33

4-
uri_cmx = 'https://msesandbox.cisco.com/api/contextaware/v1/maps/info/DevNetCampus'
4+
uri_cmx = 'https://devnetapi.cisco.com/sandbox/mse/api/config/v1/maps/info/CiscoCampus'
55

66

77
# Let's wrap our common get functionality in a function definition
88
def get_content(uri):
99
req = Request(uri)
10-
req.add_header('Authorization', 'Basic bGVhcm5pbmc6bGVhcm5pbmc==')
11-
req.add_header('Accept', 'application/json')
10+
req.add_header('Authorization', 'Basic bGVhcm5pbmc6bGVhcm5pbmc=')
11+
# req.add_header('Accept', 'application/json')
1212
response = urlopen(req)
1313
response_string = response.read().decode("utf-8")
1414
response.close()
1515
return response_string
1616

17+
1718
json_object = json.loads(get_content(uri_cmx))
1819

1920
building_names = []
2021

21-
buildings = json_object["Campus"]["Building"]
22+
buildings = json_object["buildingList"]
2223
for building in buildings:
2324
building_names.append(building["name"])
2425

2526
print(building_names)
2627
print(type(building_names))
2728

28-
#for building_name in building_names:
29-
# building_uri = uri_cmx + "/" + building_name
30-
# print(building_uri)
31-
# print(get_content(building_uri))
29+
# for building_name in building_names:
30+
# building_uri = uri_cmx + "/" + building_name
31+
# print(building_uri)
32+
# print(get_content(building_uri))
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from urllib.request import Request, urlopen
22

3-
4-
req = Request('https://msesandbox.cisco.com/api/contextaware/v1/maps/info/DevNetCampus/DevNetBuilding/DevNetZone')
5-
req.add_header('Authorization', 'Basic bGVhcm5pbmc6bGVhcm5pbmc==')
3+
req = Request('https://devnetapi.cisco.com/sandbox/mse/api/config/v1/maps/info/DevNetCampus/DevNetBuilding/DevNetZone')
4+
req.add_header('Authorization', 'Basic bGVhcm5pbmc6bGVhcm5pbmc=')
65
response = urlopen(req)
7-
responseString = response.read().decode("utf-8")
8-
print(responseString)
9-
response.close()
6+
response_string = response.read().decode('utf-8')
7+
print(response_string)
8+
response.close()
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
from urllib.request import Request, urlopen
2-
req = Request('https://msesandbox.cisco.com/api/contextaware/v1/maps/info/DevNetCampus/DevNetBuilding/DevNetZone')
3-
req.add_header('Authorization', 'Basic bGVhcm5pbmc6bGVhcm5pbmc==')
2+
import json
3+
4+
req = Request('https://devnetapi.cisco.com/sandbox/mse/api/config/v1/maps/info/DevNetCampus/DevNetBuilding/DevNetZone')
5+
req.add_header('Authorization', 'Basic bGVhcm5pbmc6bGVhcm5pbmc=')
46
req.add_header('Accept', 'application/json')
57
response = urlopen(req)
6-
responseString = response.read().decode("utf-8")
7-
print(responseString)
8-
response.close()
8+
response_string = response.read().decode('utf-8')
9+
# print(response_string)
10+
json_object = json.loads(response_string)
11+
print(json.dumps(json_object, sort_keys=True, indent=4))
12+
response.close()
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
from urllib.request import Request, urlopen
22
import json
3-
req = Request('https://msesandbox.cisco.com/api/contextaware/v1/maps/info/DevNetCampus/DevNetBuilding/DevNetZone')
4-
req.add_header('Authorization', 'Basic bGVhcm5pbmc6bGVhcm5pbmc==')
3+
4+
req = Request('https://devnetapi.cisco.com/sandbox/mse/api/config/v1/maps/info/DevNetCampus/DevNetBuilding/DevNetZone')
5+
req.add_header('Authorization', 'Basic bGVhcm5pbmc6bGVhcm5pbmc=')
56
req.add_header('Accept', 'application/json')
67
response = urlopen(req)
7-
responseString = response.read().decode("utf-8")
8-
#print(responseString)
9-
jsonObject = json.loads(responseString)
10-
print(json.dumps(jsonObject, sort_keys=True, indent=4))
11-
response.close()
8+
response_string = response.read().decode("utf-8")
9+
# print(responseString)
10+
json_object = json.loads(response_string)
11+
print(json_object)
12+
print(json.dumps(json_object, sort_keys=True, indent=4))
13+
access_points = json_object['accessPoints']
14+
for ap in access_points:
15+
print('Access Point: ' + ap['name'] + '\t mac: ' + ap['radioMacAddress'])
16+
17+
response.close()

coding202-parsing-json/get-ap-json-4.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

coding202-parsing-json/get-cmx-json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from urllib.request import Request, urlopen
22
import json
33

4-
req = Request('https://msesandbox.cisco.com/api/contextaware/v1/maps')
4+
req = Request('https://devnetapi.cisco.com/sandbox/mse/api/config/v1/maps')
55
req.add_header('Authorization', 'Basic bGVhcm5pbmc6bGVhcm5pbmc==')
66
req.add_header('Accept', 'application/json')
77

0 commit comments

Comments
 (0)