51Degrees Device Detection Python  4.1Newer Version 4.2

Device Detection services for 51Degrees Pipeline

cloud/taclookup.py

This example shows how to use the 51Degrees Cloud service to lookup the details of a device based on a given 'TAC'. More background information on TACs can be found through various online sources such as Wikipedia.

To run this example, you will need to create a resource key. The resource key is used as shorthand to store the particular set of properties you are interested in as well as any associated license keys that entitle you to increased request limits and/or paid-for properties.

You can create a resource key using the 51Degrees Configurator.

Example output:

1 This example shows the details of devices associated with a given 'Type Allocation Code' or 'TAC'.
2 More background information on TACs can be found through various online sources such as Wikipedia: https://en.wikipedia.org/wiki/Type_Allocation_Code
3 ----------------------------------------
4 Which devices are associated with the tac: 35925406
5 Apple ['iPhone 6'] A1586
1 # *********************************************************************
2 # This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3 # Copyright 2019 51 Degrees Mobile Experts Limited, 5 Charlotte Close,
4 # Caversham, Reading, Berkshire, United Kingdom RG4 7BY.
5 #
6 # This Original Work is licensed under the European Union Public Licence (EUPL)
7 # v.1.2 and is subject to its terms as set out below.
8 #
9 # If a copy of the EUPL was not distributed with this file, You can obtain
10 # one at https://opensource.org/licenses/EUPL-1.2.
11 #
12 # The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13 # amended by the European Commission) shall be deemed incompatible for
14 # the purposes of the Work and the provisions of the compatibility
15 # clause in Article 5 of the EUPL shall not apply.
16 #
17 # If using the Work as, or as part of, a network application, by
18 # including the attribution notice(s) required under Article 5 of the EUPL
19 # in the end user terms of the application under an appropriate heading,
20 # such notice(s) shall fulfill the requirements of that article.
21 # ********************************************************************
22 
23 
39 
40 from fiftyone_pipeline_core.pipelinebuilder import PipelineBuilder
41 from fiftyone_pipeline_cloudrequestengine.cloudrequestengine import CloudRequestEngine
42 from fiftyone_devicedetection.hardwareprofile_cloud import HardwareProfileCloud
43 
44 # You need to create a resource key at https://configure.51degrees.com
45 # and paste it into the code, replacing !!YOUR_RESOURCE_KEY!! below.
46 
47 resourceKey = "!!YOUR_RESOURCE_KEY!!"
48 
49 if resourceKey == "!!YOUR_RESOURCE_KEY!!":
50  print("""
51  You need to create a resource key at
52  https://configure.51degrees.com and paste it into the code,
53  'replacing !!YOUR_RESOURCE_KEY!!
54  make sure to include the HardwareName, HardwareProfile and HardwareVendor
55  properties used by this example
56  """)
57 else:
58 
59  # Create an instance of the cloud request engine with your resource key
60 
61  requestEngineInstance = CloudRequestEngine({
62  "resourceKey": resourceKey
63  })
64 
65  # Now create an instance of the hardwareprofile cloud engine
66 
67  hardwareProfileEngineInstance = HardwareProfileCloud()
68 
69  # Now create a pipeline and add those two engines
70  # the Cloud Request Engine needs to go first
71 
72  pipeline = PipelineBuilder().add(requestEngineInstance).add(hardwareProfileEngineInstance).build()
73 
74  # we get a tac to test
75  tac = "35925406"
76 
77  # We create a FlowData object from the pipeline
78  # this is used to add evidence to and then process
79  flowData = pipeline.create_flowdata()
80 
81  # After creating a flowdata instance, add the native model name as evidence.
82  flowData.evidence.add('query.tac', tac)
83 
84  # Now we process the FlowData to get results
85 
86  flowData.process()
87 
88  # The result is an array containing the details of any devices that match
89  # the specified tac.
90  # The code in this example iterates through this array, outputting the
91  # vendor and model of each matching device.
92 
93  print("Which devices are associated with the tac: " + tac)
94 
95  for profile in flowData.hardware.profiles:
96  hardwareVendor = profile["hardwarevendor"]
97  hardwareName = profile["hardwarename"]
98  hardwareModel = profile["hardwaremodel"]
99 
100  if (hardwareVendor.has_value and hardwareName.has_value and hardwareModel.has_value):
101  print(hardwareVendor.value() + " " + str(hardwareName.value()) +" "+ hardwareModel.value())
102  else:
103  print(hardwareVendor.no_value_message())