-
Notifications
You must be signed in to change notification settings - Fork 21
/
nostril-query
executable file
·74 lines (56 loc) · 1.8 KB
/
nostril-query
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python3
import sys
import argparse
import json
parser = argparse.ArgumentParser(prog = 'nostril-query', description = 'Construct nostr queries')
parser.add_argument('-r', '--raw', action=argparse.BooleanOptionalAction)
parser.add_argument('-a', '--authors')
parser.add_argument('-p', '--mentions')
parser.add_argument('-e', '--references')
parser.add_argument('-d', '--parameter')
parser.add_argument('-t', '--hashtag')
parser.add_argument('-i', '--ids')
parser.add_argument('-k', '--kinds')
parser.add_argument('-S', '--search')
parser.add_argument('-g',
'--generic',
nargs=2,
metavar=('tag', 'value'),
help="Generic tag query: `#<tag>: value`")
parser.add_argument('-l', '--limit', type=int)
parser.add_argument('-s', '--since', type=int)
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(",")
if args.limit is not None:
filt["limit"] = args.limit
if args.generic:
(tag, val) = args.generic
filt["#" + tag] = val.split(",")
if args.search:
filt["search"] = args.search
if args.hashtag is not None:
filt["#t"] = args.hashtag.split(",")
if args.mentions is not None:
filt["#p"] = args.mentions.split(",")
if args.references is not None:
filt["#e"] = args.references.split(",")
if args.parameter is not None:
filt["#d"] = args.parameter.split(",")
if args.kinds is not None:
kinds = args.kinds.split(",")
filt["kinds"] = [a for a in map(lambda s: int(s), kinds)]
if args.since is not None:
filt["since"] = args.since
q = ""
if args.raw is not None:
q = json.dumps(filt)
else:
q = json.dumps(["REQ","nostril-query",filt])
print(q)