This example is designed to output location data using the client-side evidence feature of the pipeline. This example uses the client-side evidence feature of the Pipeline to get location information from the client. This information is used to populate properties containing JavaScript snippets, which are then bundled together into a single JavaScript block by the 'JsonBundler' and 'JavaScriptBuilder' elements. This JavaScript is then used to obtain the additional evidence from the client and pass it back to the server. The Pipeline running on the server then processes this evidence to populate a new JSON result object that is returned to the client.
34 from fiftyone_location.location_pipelinebuilder
import LocationPipelineBuilder
35 from fiftyone_pipeline_core.web
import webevidence
44 if "resource_key" in os.environ:
45 resource_key = os.environ[
"resource_key"]
47 resource_key =
"!!YOUR_RESOURCE_KEY!!" 49 if resource_key ==
"!!YOUR_RESOURCE_KEY!!":
51 You need to create a resource key at 52 https://configure.51degrees.com and paste it into the code, 53 'replacing !!YOUR_RESOURCE_KEY!! 54 To get a resourcekey with the properties used in this example go to https://configure.51degrees.com/GCrtGh1L 60 javascript_builder_settings = {
64 pipeline = LocationPipelineBuilder(resource_key=resource_key, settings={
"javascript_builder_settings": javascript_builder_settings}).build()
66 from flask
import Flask, request
73 @app.route(
'/json', methods=[
'POST'])
77 flowData = pipeline.create_flowdata()
82 flowData.evidence.add_from_dict(webevidence(request))
88 return json.dumps(flowData.jsonbundler.json)
92 def getValueHelper(flowdata, engine, propertyKey):
94 engineProperties = getattr(flowdata, engine)
96 propertyValue = getattr(engineProperties, propertyKey)
98 if propertyValue.hasValue():
99 return propertyValue.value()
101 return propertyValue.no_value_message()
110 flowData = pipeline.create_flowdata()
115 flowData.evidence.add_from_dict(webevidence(request))
126 output += flowData.javascriptbuilder.javascript
127 output +=
"</script>" 130 output +=
"<h1>Client side evidence</h1>" 138 <p>After you select the "use my location" button below, client side JavaScript will 139 update the country field using this information.</p> 141 <p>Country: <span id=country></span></p> 143 <button type="button" onclick="getLocation()">Use my location</button> 147 let getLocation = function() { 148 fod.complete(function (data) { 149 document.getElementById("country").innerHTML = data.location.country