\r\n

51Degrees Device Detection Python  4.3

Device Detection services for 51Degrees Pipeline

hash/metadata.py

This example shows how to retrieve property meta data from 51Degrees on-premise device detection. This feature can be used to get information such as the category that a property belongs to or the possible values a property can have. (As of the current data file. If the data file is updated, the possible values for a property can change)

Expected output:

1 [List of properties with names and categories]
2 
3 Does user agent Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C114 support svg? :
4 true
5 Does user agent Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C114 support video? :
6 true
7 Does user agent Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C114 support supportstls/ssl? :
8 true
9 Does user agent Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C114 support supportswebgl? :
10 true
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 
43 
44 
45 from fiftyone_devicedetection_onpremise.devicedetection_onpremise_pipelinebuilder import DeviceDetectionOnPremisePipelineBuilder
46 
47 # First create the device detection pipeline with the desired settings.
48 
49 data_file = "fiftyone_devicedetection_onpremise/device-detection-cxx/device-detection-data/51Degrees-LiteV4.1.hash"
50 
51 pipeline = DeviceDetectionOnPremisePipelineBuilder(
52  data_file_path = data_file,
53  licence_keys = "",
54  performance_profile = 'MaxPerformance',
55  auto_update=False).build()
56 
57 # Now we see what properties are available in the pipeline
58 
59 properties = pipeline.get_properties()
60 
61 # Now we find out the details of the properties in the device engine
62 
63 for property_key, property_meta in properties["device"].items():
64  print(property_key + " of category " + property_meta["category"])
65 
66 # Now we can take a User-Agent, run it through this pipeline and check
67 # the supported media properties against it
68 
69 # First we create a FlowData object from the pipeline
70 flowdata = pipeline.create_flowdata()
71 
72 # Then we add the User-Agent we are interested in as evidence
73 iphone_ua = "Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C114"
74 
75 flowdata.evidence.add("header.user-agent", iphone_ua)
76 
77 # Now we process the FlowData using the engines in the Pipeline
78 
79 flowdata.process()
80 
81 # To get all properties of a specific category, we can use the "getWhere" function
82 
83 mediaSupport = flowdata.get_where("category", "Supported Media")
84 
85 for supportedMediaProperty, supportedValue in mediaSupport.items():
86  print("Does User-Agent " + iphone_ua + " support " + supportedMediaProperty + "?")
87  if supportedValue.has_value():
88  print(supportedValue.value())
89  else:
90  print(supportedValue.no_value_message())
91