Getting Started Console Example - On-premise This example shows how to use 51Degrees On-premise device detection to determine details about a device based on its User-Agent and User-Agent Client Hint HTTP header values.
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
44 from fiftyone_pipeline_core.logger
import Logger
48 class GettingStartedConsole():
49 def run(self, data_file, logger, output):
55 pipeline = DeviceDetectionPipelineBuilder(
56 data_file_path = data_file,
63 performance_profile =
"MaxPerformance",
66 usage_sharing =
False,
69 licence_keys =
"").add_logger(logger).
build()
71 ExampleUtils.check_data_file(pipeline, logger)
74 for values
in EVIDENCE_VALUES:
75 self.analyseEvidence(values, pipeline, output)
77 def analyseEvidence(self, evidence, pipeline, output):
86 data = pipeline.create_flowdata()
91 message.append(
"Input values:\n")
93 message.append(f
"\t{key}: {evidence[key]}\n")
95 output(
"".join(message))
98 data.evidence.add_from_dict(evidence)
104 message.append(
"Results:\n")
116 self.outputValue(
"Mobile Device", device.ismobile, message)
117 self.outputValue(
"Platform Name", device.platformname, message)
118 self.outputValue(
"Platform Version", device.platformversion, message)
119 self.outputValue(
"Browser Name", device.browsername, message)
120 self.outputValue(
"Browser Version", device.browserversion, message)
121 output(
"".join(message))
123 def outputValue(self, name, value, message):
132 f
"\t{name}: {value.value()}\n" if value.has_value()
133 else f
"\t{name}: {value.no_value_message()}\n")
145 data_file = argv[0]
if len(argv) > 0
else ExampleUtils.find_file(LITE_DATAFILE_NAME)
148 logger = Logger(min_level=
"info")
150 if (data_file !=
None):
151 GettingStartedConsole().
run(data_file, logger,
print)
154 "Failed to find a device detection " +
155 "data file. Make sure the device-detection-data " +
156 "submodule has been updated by running " +
157 "`git submodule update --recursive`.")
159 if __name__ ==
"__main__":