2022-11-17 20:43:50 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import argparse
|
|
|
|
import json
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(prog = 'nostril-query', description = 'Construct nostr queries')
|
2024-02-13 18:39:45 -05:00
|
|
|
parser.add_argument('-r', '--raw', action=argparse.BooleanOptionalAction)
|
2022-11-17 20:43:50 -05:00
|
|
|
parser.add_argument('-a', '--authors')
|
|
|
|
parser.add_argument('-p', '--mentions')
|
|
|
|
parser.add_argument('-e', '--references')
|
2023-03-05 11:00:31 -05:00
|
|
|
parser.add_argument('-d', '--parameter')
|
2022-11-17 20:43:50 -05:00
|
|
|
parser.add_argument('-t', '--hashtag')
|
|
|
|
parser.add_argument('-i', '--ids')
|
2022-11-17 21:12:56 -05:00
|
|
|
parser.add_argument('-k', '--kinds')
|
2024-09-30 14:33:47 -04:00
|
|
|
parser.add_argument('-S', '--search')
|
2022-11-17 20:43:50 -05:00
|
|
|
parser.add_argument('-g',
|
|
|
|
'--generic',
|
|
|
|
nargs=2,
|
|
|
|
metavar=('tag', 'value'),
|
|
|
|
help="Generic tag query: `#<tag>: value`")
|
|
|
|
parser.add_argument('-l', '--limit', type=int)
|
2023-05-07 01:25:44 -04:00
|
|
|
parser.add_argument('-s', '--since', type=int)
|
2022-11-17 20:43:50 -05:00
|
|
|
|
|
|
|
def usage():
|
|
|
|
parser.print_help()
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
filt = {}
|
|
|
|
|
|
|
|
if args.authors:
|
|
|
|
filt["authors"] = args.authors.split(",")
|
|
|
|
|
|
|
|
if args.ids:
|
|
|
|
filt["ids"] = args.ids.split(",")
|
|
|
|
|
2022-11-21 19:28:48 -05:00
|
|
|
if args.limit is not None:
|
2022-11-17 20:43:50 -05:00
|
|
|
filt["limit"] = args.limit
|
|
|
|
|
|
|
|
if args.generic:
|
|
|
|
(tag, val) = args.generic
|
|
|
|
filt["#" + tag] = val.split(",")
|
|
|
|
|
2024-02-13 18:38:53 -05:00
|
|
|
if args.search:
|
|
|
|
filt["search"] = args.search
|
|
|
|
|
2022-11-21 19:28:48 -05:00
|
|
|
if args.hashtag is not None:
|
2022-11-17 20:43:50 -05:00
|
|
|
filt["#t"] = args.hashtag.split(",")
|
|
|
|
|
2022-11-21 19:28:48 -05:00
|
|
|
if args.mentions is not None:
|
2022-11-17 20:43:50 -05:00
|
|
|
filt["#p"] = args.mentions.split(",")
|
|
|
|
|
2022-11-21 19:28:48 -05:00
|
|
|
if args.references is not None:
|
2022-11-17 20:43:50 -05:00
|
|
|
filt["#e"] = args.references.split(",")
|
|
|
|
|
2023-03-05 11:00:31 -05:00
|
|
|
if args.parameter is not None:
|
|
|
|
filt["#d"] = args.parameter.split(",")
|
|
|
|
|
2022-11-21 19:28:48 -05:00
|
|
|
if args.kinds is not None:
|
2022-11-17 21:12:56 -05:00
|
|
|
kinds = args.kinds.split(",")
|
|
|
|
filt["kinds"] = [a for a in map(lambda s: int(s), kinds)]
|
2022-11-17 20:43:50 -05:00
|
|
|
|
2023-05-07 01:25:44 -04:00
|
|
|
if args.since is not None:
|
|
|
|
filt["since"] = args.since
|
|
|
|
|
2024-02-13 18:39:45 -05:00
|
|
|
q = ""
|
|
|
|
if args.raw is not None:
|
|
|
|
q = json.dumps(filt)
|
|
|
|
else:
|
|
|
|
q = json.dumps(["REQ","nostril-query",filt])
|
|
|
|
|
2022-11-17 20:43:50 -05:00
|
|
|
print(q)
|