\r\n

51Degrees Device Detection Python  4.3

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_cloud.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 # Alternatively, add a resource_key environment variable
47 import os
48 if "resource_key" in os.environ:
49  resource_key = os.environ["resource_key"]
50 else:
51  resource_key = "!!YOUR_RESOURCE_KEY!!"
52 
53 if resource_key == "!!YOUR_RESOURCE_KEY!!":
54  print("""
55  You need to create a resource key at
56  https://configure.51degrees.com and paste it into the code,
57  'replacing !!YOUR_RESOURCE_KEY!!
58  make sure to include the HardwareName, HardwareProfile and HardwareVendor
59  properties used by this example
60  """)
61 else:
62 
63  # Create an instance of the cloud request engine with your resource key
64 
65  request_engine_instance = CloudRequestEngine({
66  "resource_key": resource_key
67  })
68 
69  # Now create an instance of the hardwareprofile cloud engine
70 
71  hardware_profile_engine_instance = HardwareProfileCloud()
72 
73  # Now create a pipeline and add those two engines
74  # the Cloud Request Engine needs to go first
75 
76  pipeline = PipelineBuilder().add(request_engine_instance).add(hardware_profile_engine_instance).build()
77 
78  # we get a tac to test
79  tac = "35925406"
80 
81  # We create a FlowData object from the pipeline
82  # this is used to add evidence to and then process
83  flowdata = pipeline.create_flowdata()
84 
85  # After creating a flowdata instance, add the native model name as evidence.
86  flowdata.evidence.add('query.tac', tac)
87 
88  # Now we process the FlowData to get results
89 
90  flowdata.process()
91 
92  # The result is an array containing the details of any devices that match
93  # the specified tac.
94  # The code in this example iterates through this array, outputting the
95  # vendor and model of each matching device.
96 
97  print("Which devices are associated with the tac: " + tac)
98 
99  for profile in flowdata.hardware.profiles:
100  hardwarevendor = profile["hardwarevendor"]
101  hardwarename = profile["hardwarename"]
102  hardwaremodel = profile["hardwaremodel"]
103 
104  if (hardwarevendor.has_value and hardwarename.has_value and hardwaremodel.has_value):
105  print(hardwarevendor.value() + " " + str(hardwarename.value()) +" "+ hardwaremodel.value())
106  else:
107  print(hardwarevendor.no_value_message())