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
42 from ..example_utils
import ExampleUtils
43 from fiftyone_pipeline_core.logger
import Logger
44 from fiftyone_pipeline_core.pipelinebuilder
import PipelineBuilder
45 from fiftyone_pipeline_cloudrequestengine.cloudrequestengine
import CloudRequestEngine
49 class NativeModelLookupConsole():
50 def run(self, resource_key, logger, output, cloudEndPoint = ""):
52 output(
"This example shows the details of devices " +
53 "associated with a given 'native model name'.")
54 output(
"The native model name can be retrieved by " +
55 "code running on the device (For example, a mobile app).")
56 output(
"For Android devices, see " +
57 "https://developer.android.com/reference/android/os/Build#MODEL")
58 output(
"For iOS devices, see " +
59 "https://gist.github.com/soapyigu/c99e1f45553070726f14c1bb0a54053b#file-machinename-swift")
60 output(
"----------------------------------------")
66 cloudRequestEngineSettings = {
"resource_key": resource_key }
71 cloudRequestEngineSettings[
"cloud_endpoint"] = cloudEndPoint
74 cloudEngine = CloudRequestEngine(cloudRequestEngineSettings)
77 propertyKeyedEngine = HardwareProfileCloud()
79 pipeline = PipelineBuilder().add_logger(logger).add(cloudEngine).add(propertyKeyedEngine).
build()
82 self.analyseModel(self._nativeModel1, pipeline, output)
84 self.analyseModel(self._nativeModel2, pipeline, output)
86 def analyseModel(self, nativemodel, pipeline, output):
88 data = pipeline.create_flowdata()
90 data.evidence.add(Constants.EVIDENCE_QUERY_NATIVE_MODEL_KEY, nativemodel)
94 result = data.hardware
95 output(
"Which devices are associated with the " +
96 f
"native model name '{nativemodel}'?")
100 for device
in result.profiles:
101 vendor = ExampleUtils.get_human_readable(device,
"hardwarevendor")
102 name = ExampleUtils.get_human_readable(device,
"hardwarename")
103 model = ExampleUtils.get_human_readable(device,
"hardwaremodel")
104 output(f
"\t{vendor} {name} ({model})")
107 _nativeModel1 =
"SC-03L" 108 _nativeModel2 =
"iPhone11,8" 113 resource_key = argv[0]
if len(argv) > 0
else ExampleUtils.get_resource_key()
119 NativeModelLookupConsole().
run(resource_key, logger,
print)
122 "No resource key specified on the command line or in the " +
123 f
"environment variable '{ExampleUtils.RESOURCE_KEY_ENV_VAR}'. " +
124 "The 51Degrees cloud service is accessed using a 'ResourceKey'. " +
125 "For more information " +
126 "see https://51degrees.com/documentation/_info__resource_keys.html. " +
127 "Native model lookup is not available as a free service. This means that " +
128 "you will first need a license key, which can be purchased from our " +
129 "pricing page: https://51degrees.com/pricing. Once this is done, a resource " +
130 "key with the properties required by this example can be created at " +
131 "https://configure.51degrees.com/QKyYH5XT. You can now populate the " +
132 "environment variable mentioned at the start of this message with the " +
133 "resource key or pass it as the first argument on the command line.")
135 if __name__ ==
"__main__":