nostril

A C cli tool for creating nostr events
git clone git://jb55.com/nostril
Log | Files | Refs | Submodules | README | LICENSE

nostril-query (1508B)


      1 #!/usr/bin/env python3
      2 
      3 import sys
      4 import argparse
      5 import json
      6 
      7 parser = argparse.ArgumentParser(prog = 'nostril-query', description = 'Construct nostr queries')
      8 parser.add_argument('-a', '--authors')
      9 parser.add_argument('-p', '--mentions')
     10 parser.add_argument('-e', '--references')
     11 parser.add_argument('-d', '--parameter')
     12 parser.add_argument('-t', '--hashtag')
     13 parser.add_argument('-i', '--ids')
     14 parser.add_argument('-k', '--kinds')
     15 parser.add_argument('-g', 
     16                     '--generic',
     17                     nargs=2,
     18                     metavar=('tag', 'value'),
     19                     help="Generic tag query: `#<tag>: value`")
     20 parser.add_argument('-l', '--limit', type=int)
     21 
     22 def usage():
     23     parser.print_help()
     24     sys.exit(1)
     25 
     26 args = parser.parse_args()
     27 
     28 filt = {}
     29 
     30 if args.authors:
     31     filt["authors"] = args.authors.split(",")
     32 
     33 if args.ids:
     34     filt["ids"] = args.ids.split(",")
     35 
     36 if args.limit is not None:
     37     filt["limit"] = args.limit
     38 
     39 if args.generic:
     40     (tag, val) = args.generic
     41     filt["#" + tag] = val.split(",")
     42 
     43 if args.hashtag is not None:
     44     filt["#t"] = args.hashtag.split(",")
     45 
     46 if args.mentions is not None:
     47     filt["#p"] = args.mentions.split(",")
     48 
     49 if args.references is not None:
     50     filt["#e"] = args.references.split(",")
     51 
     52 if args.parameter is not None:
     53     filt["#d"] = args.parameter.split(",")
     54 
     55 if args.kinds is not None:
     56     kinds = args.kinds.split(",")
     57     filt["kinds"] = [a for a in map(lambda s: int(s), kinds)]
     58 
     59 q = json.dumps(["REQ","nostril-query",filt])
     60 print(q)