Commit d1bf205e authored by Federico Sismondi's avatar Federico Sismondi

Update() entities init values

parent be7f3218
...@@ -51,18 +51,39 @@ weather_entities = [ ...@@ -51,18 +51,39 @@ weather_entities = [
extra_args = { extra_args = {
'WeatherObserved': 'WeatherObserved':
{ {
'dateObserved': datetime.datetime.utcnow().isoformat(), 'dateObserved': datetime.datetime.utcnow().isoformat(), # mandatory
'location': {'type': 'Point', 'coordinates': [6.1385878, 46.1838613]} 'location': {'type': 'Point', 'coordinates': [6.1385878, 46.1838613]}, # mandatory
'source': 'misc.',
'illuminance': 0,
'temperature': 0.0,
'precipitation': 0,
'atmosphericPressure': 0.0,
'windSpeed': 0,
'pressureTendency': 0.0,
'relativeHumidity': 0,
}, },
'WeatherForecast': 'WeatherForecast':
{ {
'dateIssued': datetime.datetime.utcnow().isoformat(), 'dateIssued': datetime.datetime.utcnow().isoformat(), # mandatory
'address': { 'address': {
'streetAddress': 'Place de Sardaigne', 'streetAddress': 'Place de Sardaigne',
'adressLocality': 'Carouge', 'addressLocality': 'Carouge',
'addressCountry': 'Switzerland' 'addressCountry': 'Switzerland'
}, # mandatory
"dayMinimum": {
"feelsLikeTemperature": 11,
"temperature": 11,
"relativeHumidity": 0.7
},
"dayMaximum": {
"feelsLikeTemperature": 15,
"temperature": 15,
"relativeHumidity": 0.9
}, },
"precipitationProbability": 0.15,
'windSpeed': 0,
} }
} }
...@@ -88,14 +109,15 @@ for urn, schema, keep_history in weather_entities: ...@@ -88,14 +109,15 @@ for urn, schema, keep_history in weather_entities:
) )
entities.append(instance) entities.append(instance)
# create entities in IoT platform
print("Updating entities")
# log created entities # log created entities
print('Entities list (len {}) ready to be pushed to platform '.format(len(entities))) print('Entities list (len {}) ready to be pushed to platform '.format(len(entities)))
for i in entities: for i in entities:
pprint(i, indent=4) pprint(i, indent=4)
# create entities in IoT platform
print("%s - updating entities" % datetime.datetime.now().replace(microsecond=0).isoformat())
operation = { operation = {
"actionType": "append", "actionType": "append",
"entities": entities "entities": entities
...@@ -105,9 +127,12 @@ try: ...@@ -105,9 +127,12 @@ try:
r = requests.post(url=URL_BASE + "/v2/op/update?options=keyValues", headers=h, json=operation) r = requests.post(url=URL_BASE + "/v2/op/update?options=keyValues", headers=h, json=operation)
if not (200 <= r.status_code < 300): if not (200 <= r.status_code < 300):
print("HTTP status code not 2xx, something went wrong..")
print(r.status_code) print(r.status_code)
print(r.reason) print(r.reason)
print(r.json()) print(r.json())
else:
print("Entities updated (HTTP response is 2xx)")
except StopIteration: except StopIteration:
pass pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment