-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpath-create.py
More file actions
31 lines (26 loc) · 1.16 KB
/
Copy pathpath-create.py
File metadata and controls
31 lines (26 loc) · 1.16 KB
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
#
# Create paths from info in "paths.csv"
# (Note: No space before or after commas in paths.csv)
# (Requests status codes -
# https://github.com/requests/requests/blob/master/requests/status_codes.py)
#
import csv
from api_fns import *
with open('paths.csv', mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file)
for row in csv_reader:
# pp_json(row)
r1 = create_network_path(row['org_id'], row['source_mp'],
row['target'])
if r1.status_code == requests.codes.created:
print('Created: org/src/targ {}/{}/{}'
.format(row['org_id'], row['source_mp'], row['target']))
else:
print('Unable to create: {}'.format(r1.json()['messages'][0]))
network_path_id = get_network_path_id(row['org_id'], row['source_mp'],
row['target'])
r2 = add_network_path_location(network_path_id, row['location'])
if r2.status_code == requests.codes.ok:
print('Added location successfully: {}.'.format(row['location']))
else:
print('Unable to add location: {}.'.format(row['location']))