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.
38 from pathlib
import Path
40 from ..example_utils
import ExampleUtils
41 from fiftyone_pipeline_core.logger
import Logger
42 from fiftyone_pipeline_core.pipelinebuilder
import PipelineBuilder
43 from fiftyone_devicedetection_shared.constants
import Constants
45 class TacLookupConsole():
46 def run(self, config, logger, output):
48 output(
"This example shows the details of devices " +
49 "associated with a given 'Type Allocation Code' or 'TAC'.")
50 output(
"More background information on TACs can be " +
51 "found through various online sources such as Wikipedia: " +
52 "https://en.wikipedia.org/wiki/Type_Allocation_Code")
53 output(
"----------------------------------------")
62 pipeline = PipelineBuilder().add_logger(logger).build_from_configuration(config)
65 self.analyseTac(self._tac1, pipeline, output)
67 self.analyseTac(self._tac2, pipeline, output)
69 def analyseTac(self, tac, pipeline, output):
71 data = pipeline.create_flowdata()
73 data.evidence.add(Constants.EVIDENCE_QUERY_TAC_KEY, tac)
77 result = data.hardware
78 output(f
"Which devices are associated with the TAC '{tac}'?")
82 for device
in result.profiles:
83 vendor = ExampleUtils.get_human_readable(device,
"hardwarevendor")
84 name = ExampleUtils.get_human_readable(device,
"hardwarename")
85 model = ExampleUtils.get_human_readable(device,
"hardwaremodel")
86 output(f
"\t{vendor} {name} ({model})")
95 resource_key = argv[0]
if len(argv) > 0
else ExampleUtils.get_resource_key()
101 configFile = Path(__file__).resolve().parent.joinpath(
"taclookup_console.json").read_text()
102 config = json5.loads(configFile)
105 resourceKeyFromConfig = ExampleUtils.get_resource_key_from_config(config)
106 configHasKey = resourceKeyFromConfig
and resourceKeyFromConfig.startswith(
"!!") ==
False 110 if configHasKey ==
False:
111 ExampleUtils.set_resource_key_in_config(config, resource_key)
114 if not ExampleUtils.get_resource_key_from_config(config):
116 "No resource key specified on the command line or in " +
117 f
"the environment variable '{ExampleUtils.RESOURCE_KEY_ENV_VAR}'. " +
118 "The 51Degrees cloud service is accessed using a 'ResourceKey'. " +
119 "For more information see " +
120 "http://51degrees.com/documentation/_info__resource_keys.html. " +
121 "TAC lookup is not available as a free service. This means " +
122 "that you will first need a license key, which can be purchased " +
123 "from our pricing page: http://51degrees.com/pricing. Once this is " +
124 "done, a resource key with the properties required by this example " +
125 "can be created at https://configure.51degrees.com/QKyYH5XT. You " +
126 "can now populate the environment variable mentioned at the start " +
127 "of this message with the resource key or pass it as the first " +
128 "argument on the command line.")
130 TacLookupConsole().run(config, logger,
print)
132 if __name__ ==
"__main__":