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