This example shows how the 51Degrees device detection engine deals with
evidence that does not match any known device.
In this scenario, 'HasValue' can be used to check if the property has been
populated by the engine. If it hasn't then 'NoValueMessage' can be used
to get the reason why.
39 from fiftyone_devicedetection_cloud.devicedetection_cloud_pipelinebuilder
import DeviceDetectionCloudPipelineBuilder
47 if "resource_key" in os.environ:
48 resource_key = os.environ[
"resource_key"]
50 resource_key =
"!!YOUR_RESOURCE_KEY!!" 52 if resource_key ==
"!!YOUR_RESOURCE_KEY!!":
54 You need to create a resource key at 55 https://configure.51degrees.com and paste it into the code, 56 'replacing !!YOUR_RESOURCE_KEY!! 57 To include the properties used in this example, go to https://configure.51degrees.com/bxXqZhLT 61 pipeline = DeviceDetectionCloudPipelineBuilder({
62 "resource_key": resource_key
68 flowdata1 = pipeline.create_flowdata()
72 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 flowdata1.evidence.add(
"header.user-agent", iphone_ua)
85 print(
"Is User-Agent " + iphone_ua +
" a mobile device?: ")
86 if flowdata1.device.ismobile.has_value():
87 print(flowdata1.device.ismobile.value())
90 print(flowdata1.device.ismobile.no_value_message())
96 flowdata2 = pipeline.create_flowdata()
98 flowdata2.evidence.add(
"header.user-agent", badUA)
102 print(
"Is User-Agent " + badUA +
" a mobile device?: ")
103 if flowdata2.device.ismobile.has_value():
104 print(flowdata2.device.ismobile.value())
107 print(flowdata2.device.ismobile.no_value_message())