From f7d25f5c4c3cf44417ce66a8d2ea224e339da6de Mon Sep 17 00:00:00 2001 From: nebula Date: Sun, 20 Apr 2025 19:51:37 +0000 Subject: [PATCH] initial commit --- bink.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 bink.py diff --git a/bink.py b/bink.py new file mode 100644 index 0000000..a97e350 --- /dev/null +++ b/bink.py @@ -0,0 +1,54 @@ +# {"title": "this is a test", "body": "this is text"}, + +import json +from glob import glob +from time import time_ns +import os + +home = os.path.expanduser("~/.bink") +my_user = home.split("/")[2] + +max_title_length = 120 +max_body_length = 64_000 + +try: + os.mkdir(home) +except FileExistsError: + pass + +def post_object(path): + split = path.split("/") + # example input: /home/nebula/.bink/999 + # output: (999, "nebula", "/home/nebula/.bink/999") + return (int(split[-1]), split[2], path) + +def generate_feed(): + posts = [post_object(path) for path in glob("/home/**/.bink/*")] + posts.sort(key=lambda x: x[0]) + tree = {} + for time, user, path in posts: + # try: + with open(path, "r") as f: + data = json.load(f) + # except + obj = { + "user": user, + "time": time, + "body": data["body"], + "title": data["title"] + } + try: + tree[data["title"]].append(obj) + except KeyError: + tree[data["title"]] = [obj] + return tree + +def create_post(title, body): + thread = { + "body": body[:max_body_length], + "title": title[:max_title_length] + } + with open(f"{home}/{time_ns()}", "w") as f: + json.dump(f, indent=2) + +print(generate_feed())