|
1 | 1 | from urllib.request import Request, urlopen |
2 | 2 | import json |
3 | 3 |
|
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 | + |
5 | 6 |
|
6 | 7 | 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 | + |
14 | 16 |
|
15 | | -jsonObject = json.loads(get_content(uri)) |
| 17 | +json_object = json.loads(get_content(uri)) |
16 | 18 |
|
17 | 19 | building_names = [] |
18 | 20 |
|
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"]) |
22 | 24 |
|
| 25 | +# Print out the building names found - this is a Python list |
23 | 26 | 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)) |
0 commit comments