-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopulate_platform.py
executable file
·61 lines (47 loc) · 1.99 KB
/
populate_platform.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
#!/usr/bin/python2
import xml.etree.ElementTree as ET
from sys import argv
import os
import requests
import csv
_, filename = argv
if os.environ.get('INTERSCITY_HOST') is not None:
host = os.environ['INTERSCITY_HOST']
else:
host = 'localhost:8000'
print("[I] Check if current_location capability exists")
reponse = requests.get('http://' + host +
'/catalog/capabilities/current_location')
if reponse.status_code == 404:
print("[I] Creating current_location capability")
capability_json = { "name": "current_location",
"description": "current location",
"capability_type": "sensor" }
response = requests.post('http://' + host + '/catalog/capabilities',
json=capability_json)
if response.status_code == 422:
print("[E] The capability current_location was not created")
exit(-1)
with open(filename) as csvfile:
reader = csv.reader(csvfile, delimiter=';')
for row in reader:
uuid = row[7]
print("[I] Check if car {0} exists".format(uuid))
response = requests.get('http://' + host +
'/catalog/resources/{0}'.format(uuid))
if response.status_code == 404:
print("[I] Create car {0}".format(uuid))
car_json = { "data": {
"description": "Car",
"uuid": uuid,
"capabilities": [ "current_location" ],
"status": "active",
"lat": -23,
"lon": -46
}
}
response = requests.post('http://' + host + '/catalog/resources',
json=car_json)
if response.status_code == 404:
print("[E] The car {0} was not created".format(uuid))
print("[I] Finish \o/")