This example requires a local data file. The free 'Lite' data file can be acquired by
pulling the git submodules under this repository (run `git submodule update --recursive`)
or from the device-detection-data
GitHub repository.
The Lite data file is only used for illustration, and has limited accuracy and capabilities.
Find out about the more capable data files that are available on our
pricing page
79 from fiftyone_devicedetection_examples.example_utils
import ExampleUtils
80 from flask.helpers
import make_response
81 from flask
import Flask, request, render_template
82 from fiftyone_devicedetection.devicedetection_pipelinebuilder
import DeviceDetectionPipelineBuilder
93 LITE_V_4_1_HASH =
"51Degrees-LiteV4.1.hash";
96 class GettingStartedWeb():
99 def build(self, data_file):
102 javascript_builder_settings = {
110 "enable_cookies":
True 113 GettingStartedWeb.pipeline = DeviceDetectionPipelineBuilder(
114 data_file_path = data_file,
121 performance_profile =
"LowMemory",
126 javascript_builder_settings = javascript_builder_settings).build()
132 GettingStartedWeb.app.run()
137 @app.route(
'/json', methods=[
'POST'])
141 flowdata = GettingStartedWeb.pipeline.create_flowdata()
146 flowdata.evidence.add_from_dict(webevidence(request))
154 return json.dumps(flowdata.jsonbundler.json)
163 flowdata = GettingStartedWeb.pipeline.create_flowdata()
168 flowdata.evidence.add_from_dict(webevidence(request))
174 response = make_response()
182 set_response_header(flowdata, response)
185 response.set_data(render_template(
196 data_file = argv[0]
if len(argv) > 0
else ExampleUtils.find_file(LITE_V_4_1_HASH)
199 logger = logging.getLogger(
"Getting Started")
200 logger.setLevel(logging.INFO)
202 if (data_file !=
None):
203 GettingStartedWeb().build(data_file).run()
205 logger.error(
"Failed to find a device detection " +
206 "data file. Make sure the device-detection-data " +
207 "submodule has been updated by running " +
208 "`git submodule update --recursive`.")
210 if __name__ ==
"__main__":