in api-reference-examples/python/te-tag-query/TETagQuery.py [0:0]
def handle(self, args, options):
options["includeIndicatorInOutput"] = True
options["pageSize"] = 10
while True:
if len(args) == 0:
break
if args[0][0] != "-":
break
option = args[0]
args = args[1:]
if option == "-h":
self.usage(0)
elif option == "--help":
self.usage(0)
elif option == "--tagged-since":
if len(args) < 1:
self.usage(1)
options["taggedSince"] = args[0]
args = args[1:]
elif option == "--tagged-until":
if len(args) < 1:
self.usage(1)
options["taggedUntil"] = args[0]
args = args[1:]
elif option == "--created-since":
if len(args) < 1:
self.usage(1)
options["createdSince"] = args[0]
args = args[1:]
elif option == "--created-until":
if len(args) < 1:
self.usage(1)
options["createdUntil"] = args[0]
args = args[1:]
elif option == "--page-size":
if len(args) < 1:
self.usage(1)
options["pageSize"] = args[0]
args = args[1:]
elif option == "--no-print-indicator":
if len(args) < 1:
self.usage(1)
options["includeIndicatorInOutput"] = False
else:
eprint(
"%s %s: unrecognized option %s"
% (self.progName, self.verbName, option)
)
sys.exit(1)
if len(args) != 1:
self.usage(1)
tagName = args[0]
# Tagged-at filtering is done server-side -- the TE /tagged_objects
# endpoint filters by tagged-at timestamps on the graph edges from tag to
# descriptor ID. An implementation detail of /tagged_objects is that it
# only yields abstract IDs; descriptor IDs to details are a separate pass
# in this design.
#
# This means that if the user wants to filter on created-at:
# * We have the invariants that created-at <= tagged-at, and tagged-at <= now.
# * If they ask for created-since t, we query the server for tagged-since t
# (which overfetches) and then we filter client-side.
# * If they as for created-until t, we query the server for tagged-until now
# (which overfetches) and then we filter client-side.
options["createdSinceEpochSeconds"] = None
options["createdUntilEpochSeconds"] = None
if options.get("createdSince") != None:
if options.get("taggedSince") != None:
eprint(
"%s %s: Please specify at most one of --tagged-since and --created-since."
% (self.progName, self.verbName)
)
sys.exit(1)
options["taggedSince"] = options["createdSince"]
options["createdSinceEpochSeconds"] = TE.Net.parseTimeStringToEpochSeconds(
options["createdSince"]
)
if options.get("createdUntil") != None:
if options.get("taggedUntil") != None:
eprint(
"%s %s: Please specify at most one of --tagged-until and --created-until."
% (self.progName, self.verbName)
)
sys.exit(1)
# keep options['taggedUntil'] = None
options["createdUntilEpochSeconds"] = TE.Net.parseTimeStringToEpochSeconds(
options["createdUntil"]
)
# Step 1: tag text to ID
# Step 2: tag ID to descriptor IDs, paginated
# Step 3: descriptor IDs to descriptor details, paginated
tag_id = TE.Net.getTagIDFromName(tagName, options["showURLs"])
if tag_id is None:
eprint('Tag "%s" not found.' % tagName)
sys.exit(1)
idProcessor = lambda idBatch: self.IDProcessor(idBatch, options)
TE.Net.processDescriptorIDsByTagID(
tag_id,
idProcessor,
verbose=options["verbose"],
showURLs=options["showURLs"],
taggedSince=options.get("taggedSince", None),
taggedUnti=options.get("taggedUntil", None),
pageSize=options["pageSize"],
)