\r\n

51Degrees Device Detection Python  4.3

Device Detection services for 51Degrees Pipeline

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