From 97578b88f0c53cf385911b8077b1ab485155ef61 Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Tue, 25 Jul 2023 17:41:04 +0200 Subject: Add krokify utility --- .local/bin/krokify | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 .local/bin/krokify diff --git a/.local/bin/krokify b/.local/bin/krokify new file mode 100755 index 0000000..a01c1f6 --- /dev/null +++ b/.local/bin/krokify @@ -0,0 +1,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() -- cgit v1.1