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
39 from fiftyone_pipeline_core.logger
import Logger
43 class GettingStartedConsole():
44 def run(self, data_file, logger, output):
50 pipeline = DeviceDetectionPipelineBuilder(
51 data_file_path = data_file,
58 performance_profile =
"LowMemory",
61 usage_sharing =
False,
64 licence_keys =
"").add_logger(logger).
build()
66 ExampleUtils.check_data_file(pipeline, logger)
69 for values
in EVIDENCE_VALUES:
70 self.analyseEvidence(values, pipeline, output)
72 def analyseEvidence(self, evidence, pipeline, output):
81 data = pipeline.create_flowdata()
86 message.append(
"Input values:\n")
88 message.append(f
"\t{key}: {evidence[key]}\n")
90 output(
"".join(message))
93 data.evidence.add_from_dict(evidence)
99 message.append(
"Results:\n")
111 self.outputValue(
"Mobile Device", device.ismobile, message)
112 self.outputValue(
"Platform Name", device.platformname, message)
113 self.outputValue(
"Platform Version", device.platformversion, message)
114 self.outputValue(
"Browser Name", device.browsername, message)
115 self.outputValue(
"Browser Version", device.browserversion, message)
116 output(
"".join(message))
118 def outputValue(self, name, value, message):
127 f
"\t{name}: {value.value()}\n" if value.has_value()
128 else f
"\t{name}: {value.no_value_message()}\n")
140 data_file = argv[0]
if len(argv) > 0
else ExampleUtils.find_file(LITE_DATAFILE_NAME)
143 logger = Logger(min_level=
"info")
145 if (data_file !=
None):
146 GettingStartedConsole().
run(data_file, logger,
print)
149 "Failed to find a device detection " +
150 "data file. Make sure the device-detection-data " +
151 "submodule has been updated by running " +
152 "`git submodule update --recursive`.")
154 if __name__ ==
"__main__":