TAC Lookup Console Example - Cloud This example shows the details of devices associated with a given 'Type Allocation Code' or 'TAC'. More background information on TACs can be found through various online sources such as Wikipedia: https://en.wikipedia.org/wiki/Type_Allocation_Code
44 from pathlib
import Path
47 from ..example_utils
import ExampleUtils
48 from fiftyone_pipeline_core.logger
import Logger
49 from fiftyone_pipeline_core.pipelinebuilder
import PipelineBuilder
52 class TacLookupConsole():
53 def run(self, config, logger, output):
55 output(
"This example shows the details of devices " +
56 "associated with a given 'Type Allocation Code' or 'TAC'.")
57 output(
"More background information on TACs can be " +
58 "found through various online sources such as Wikipedia: " +
59 "https://en.wikipedia.org/wiki/Type_Allocation_Code")
60 output(
"----------------------------------------")
69 pipeline = PipelineBuilder().add_logger(logger).build_from_configuration(config)
72 self.analyseTac(self._tac1, pipeline, output)
74 self.analyseTac(self._tac2, pipeline, output)
76 def analyseTac(self, tac, pipeline, output):
78 data = pipeline.create_flowdata()
80 data.evidence.add(Constants.EVIDENCE_QUERY_TAC_KEY, tac)
84 result = data.hardware
85 output(f
"Which devices are associated with the TAC '{tac}'?")
89 for device
in result.profiles:
90 vendor = ExampleUtils.get_human_readable(device,
"hardwarevendor")
91 name = ExampleUtils.get_human_readable(device,
"hardwarename")
92 model = ExampleUtils.get_human_readable(device,
"hardwaremodel")
93 output(f
"\t{vendor} {name} ({model})")
102 resource_key = argv[0]
if len(argv) > 0
else ExampleUtils.get_resource_key()
108 configFile = Path(__file__).resolve().parent.joinpath(
"taclookup_console.json").read_text()
109 config = json5.loads(configFile)
112 resourceKeyFromConfig = ExampleUtils.get_resource_key_from_config(config)
113 configHasKey = resourceKeyFromConfig
and resourceKeyFromConfig.startswith(
"!!") ==
False 117 if configHasKey ==
False:
118 ExampleUtils.set_resource_key_in_config(config, resource_key)
121 if not ExampleUtils.get_resource_key_from_config(config):
123 "No resource key specified on the command line or in " +
124 f
"the environment variable '{ExampleUtils.RESOURCE_KEY_ENV_VAR}'. " +
125 "The 51Degrees cloud service is accessed using a 'ResourceKey'. " +
126 "For more information see " +
127 "https://51degrees.com/documentation/_info__resource_keys.html. " +
128 "TAC lookup is not available as a free service. This means " +
129 "that you will first need a license key, which can be purchased " +
130 "from our pricing page: https://51degrees.com/pricing. Once this is " +
131 "done, a resource key with the properties required by this example " +
132 "can be created at https://configure.51degrees.com/QKyYH5XT. You " +
133 "can now populate the environment variable mentioned at the start " +
134 "of this message with the resource key or pass it as the first " +
135 "argument on the command line.")
137 TacLookupConsole().
run(config, logger,
print)
139 if __name__ ==
"__main__":