From 0e189084ccb1f0bdc9ca4b340ab69c5bcb0c5494 Mon Sep 17 00:00:00 2001 From: Alberto Abella Date: Fri, 24 May 2024 17:19:28 +0200 Subject: [PATCH] created example of code --- .../code_for_using_dataModel.Parking_ParkingSpot.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ParkingSpot/code/code_for_using_dataModel.Parking_ParkingSpot.py b/ParkingSpot/code/code_for_using_dataModel.Parking_ParkingSpot.py index beb2b86..73f92b9 100644 --- a/ParkingSpot/code/code_for_using_dataModel.Parking_ParkingSpot.py +++ b/ParkingSpot/code/code_for_using_dataModel.Parking_ParkingSpot.py @@ -24,25 +24,30 @@ # curl -X GET http://localhost:1026/ngsi-ld/v1/entities?local=true&limit=1000 # # # now the python code you can use to insert some value in the context broker according to the data model +# # Version Warning! +# # This code is designed to work with the version 0.8 of pysmartdatamodels or later +# # to work with earlier version you need to replace the import instruction for +# # from pysmartdatamodels import pysmartdatamodels as sdm # -from pysmartdatamodels import pysmartdatamodels as sdm +# +import pysmartdatamodels as sdm import subprocess serverUrl = "http://localhost:1026" # supposed that your broker is installed in localhost. Edit to match your configuration dataModel = "ParkingSpot" subject = "dataModel.Parking" -category = {'type': 'Property', 'value': ['onStreet']} +category = ['onStreet'] attribute = "category" value = category # The next line creates the query for inserting this attribute in a NGSI-LD context broker if the attribute does not exist it creates it print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True)) -refParkingSite = "{'type': 'Relationship', 'object': 'urn:ngsi-ld:ParkingSite:santander:daoiz_velarde_1_5'}" +refParkingSite = "urn:ngsi-ld:ParkingSite:santander:daoiz_velarde_1_5" attribute = "refParkingSite" value = refParkingSite # The next line creates the query for inserting this attribute in a NGSI-LD context broker if the attribute does not exist it creates it print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True)) -status = "{'type': 'Property', 'value': 'free', 'observedAt': '2018-09-21T12:00:00Z', 'parkingPermit': {'type': 'Property', 'value': 'yes'}}" +status = "free" attribute = "status" value = status # The next line creates the query for inserting this attribute in a NGSI-LD context broker if the attribute does not exist it creates it