Skip to content

Commit

Permalink
created example of code
Browse files Browse the repository at this point in the history
  • Loading branch information
albertoabellagarcia committed May 24, 2024
1 parent 5afadff commit 386f053
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,36 @@
# 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 = "SmartPointOfInteraction"
subject = "dataModel.PointOfInteraction"
applicationUrl = "{'type': 'Property', 'value': 'http://www.example.org'}"
applicationUrl = "http://www.example.org"
attribute = "applicationUrl"
value = applicationUrl
# 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))

areaCovered = {'type': 'Property', 'value': {'type': 'Polygon', 'coordinates': [[[25.774, -80.19], [18.466, -66.118], [32.321, -64.757], [25.774, -80.19]]]}}
areaCovered = {'coordinates': [[[25.774, -80.19], [18.466, -66.118], [32.321, -64.757], [25.774, -80.19]]], 'type': 'Polygon'}
attribute = "areaCovered"
value = areaCovered
# 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))

availability = "{'type': 'Property', 'value': 'Tu,Th 16:00-20:00'}"
availability = "Tu,Th 16:00-20:00"
attribute = "availability"
value = availability
# 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))

category = {'type': 'Property', 'value': ['co-creation']}
category = ['co-creation']
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
Expand Down

0 comments on commit 386f053

Please sign in to comment.