aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/krokify
blob: a01c1f61811196e1cf1ce9ccc3b96bf7ed0eca00 (plain)
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
#!/usr/bin/env python3

import argparse
import base64
import sys
import zlib

def main():
	arg_parser = argparse.ArgumentParser(
		prog='krokify',
		description='Turn a given file into a kroki link',
	)
	arg_parser.add_argument("file", default="-", help="Path to the file to krokify, or - to read from stdin")
	arg_parser.add_argument("-f", "--format", default="svg", help="Which output format to use")
	arg_parser.add_argument("-s", "--service", required=True, help="Which back-end service to use")
	arg_parser.add_argument("-u", "--base-url", default="https://kroki.tyil.nl", help="The base URL of the Kroki server")

	args = arg_parser.parse_args()

	if args.file == "-":
		stream = sys.stdin
	else:
		stream = open(args.file, "r")

	url = base64.urlsafe_b64encode(zlib.compress(stream.read().encode('utf-8'), 9)).decode('ascii')

	print(f"{args.base_url}/{args.service}/{args.format}/{url}")

if __name__ == "__main__":
    main()