This example shows how to use the 51Degrees Cloud service to lookup the details of a device based on a given 'native model name'. Native model name is a string of characters that are returned from a query to the device's OS. There are different mechanisms to get native model names for Android devices and iOS devices
41 from ..example_utils
import ExampleUtils
42 from fiftyone_pipeline_core.logger
import Logger
43 from fiftyone_pipeline_core.pipelinebuilder
import PipelineBuilder
44 from fiftyone_pipeline_cloudrequestengine.cloudrequestengine
import CloudRequestEngine
45 from fiftyone_devicedetection_shared.constants
import Constants
46 from fiftyone_devicedetection_cloud.hardwareprofile_cloud
import HardwareProfileCloud
48 class NativeModelLookupConsole():
49 def run(self, resource_key, logger, output, cloudEndPoint = ""):
51 output(
"This example shows the details of devices " +
52 "associated with a given 'native model name'.")
53 output(
"The native model name can be retrieved by " +
54 "code running on the device (For example, a mobile app).")
55 output(
"For Android devices, see " +
56 "https://developer.android.com/reference/android/os/Build#MODEL")
57 output(
"For iOS devices, see " +
58 "https://gist.github.com/soapyigu/c99e1f45553070726f14c1bb0a54053b#file-machinename-swift")
59 output(
"----------------------------------------")
65 cloudRequestEngineSettings = {
"resource_key": resource_key }
70 cloudRequestEngineSettings[
"cloud_endpoint"] = cloudEndPoint
73 cloudEngine = CloudRequestEngine(cloudRequestEngineSettings)
76 propertyKeyedEngine = HardwareProfileCloud()
78 pipeline = PipelineBuilder().add_logger(logger).add(cloudEngine).add(propertyKeyedEngine).build()
81 self.analyseModel(self._nativeModel1, pipeline, output)
83 self.analyseModel(self._nativeModel2, pipeline, output)
85 def analyseModel(self, nativemodel, pipeline, output):
87 data = pipeline.create_flowdata()
89 data.evidence.add(Constants.EVIDENCE_QUERY_NATIVE_MODEL_KEY, nativemodel)
93 result = data.hardware
94 output(
"Which devices are associated with the " +
95 f
"native model name '{nativemodel}'?")
99 for device
in result.profiles:
100 vendor = ExampleUtils.get_human_readable(device,
"hardwarevendor")
101 name = ExampleUtils.get_human_readable(device,
"hardwarename")
102 model = ExampleUtils.get_human_readable(device,
"hardwaremodel")
103 output(f
"\t{vendor} {name} ({model})")
106 _nativeModel1 =
"SC-03L" 107 _nativeModel2 =
"iPhone11,8" 112 resource_key = argv[0]
if len(argv) > 0
else ExampleUtils.get_resource_key()
118 NativeModelLookupConsole().run(resource_key, logger,
print)
121 "No resource key specified on the command line or in the " +
122 f
"environment variable '{ExampleUtils.RESOURCE_KEY_ENV_VAR}'. " +
123 "The 51Degrees cloud service is accessed using a 'ResourceKey'. " +
124 "For more information " +
125 "see http://51degrees.com/documentation/_info__resource_keys.html. " +
126 "Native model lookup is not available as a free service. This means that " +
127 "you will first need a license key, which can be purchased from our " +
128 "pricing page: http://51degrees.com/pricing. Once this is done, a resource " +
129 "key with the properties required by this example can be created at " +
130 "https://configure.51degrees.com/QKyYH5XT. You can now populate the " +
131 "environment variable mentioned at the start of this message with the " +
132 "resource key or pass it as the first argument on the command line.")
134 if __name__ ==
"__main__":