#!/usr/bin/env python3 import argparse import json import os import socketserver import tempfile from pathlib import Path ARGS = None HTML_TEMPLATE = """\
{}".format(data.decode(errors="replace")) html = HTML_TEMPLATE.format(title=title or "?", content=content) path = str(Path(ARGS.root) / "txt") if not os.path.isdir(path): os.makedirs(path) with tempfile.NamedTemporaryFile( mode="wt", dir=path, suffix=".html", delete=False ) as output_file: output_file.write(html) return output_file.name def main(): argp = argparse.ArgumentParser() argp.add_argument("root", help="root path where to put files") global ARGS ARGS = argp.parse_args() uid = os.getuid() socket_path = f"/run/user/{uid}/shr.sock" if os.path.exists(socket_path): os.unlink(socket_path) try: with socketserver.UnixStreamServer(socket_path, Handler) as server: server.serve_forever() except KeyboardInterrupt: print("Stopping server.") finally: os.unlink(socket_path) if __name__ == "__main__": main()