Add query parse script

main
Buddy Sandidge 1 year ago
parent f314c306bd
commit d7bede17a2

@ -1,3 +1,4 @@
/.idea
/README.md
/scripts/
{{- if not .include_legacy }}

2
.gitignore vendored

@ -1 +1 @@
vim/plugged
/.idea

@ -0,0 +1,31 @@
#!/usr/bin/env python3
import json
import select
import sys
import urllib.parse
def main(args=(), stdin=()):
for arg in args:
print(parse(arg))
for line in stdin:
print(parse(line))
def parse(params):
qs = urllib.parse.parse_qs(params.strip(), keep_blank_values=True)
obj = {}
for key, value in qs.items():
obj[key] = value[0] if len(value) == 1 else value
return json.dumps(obj)
def get_stdin():
found = select.select((sys.stdin,), (), (), 0.0)[0]
return found[0] if found else ()
if __name__ == "__main__":
main(sys.argv[1:], get_stdin())
Loading…
Cancel
Save