initial commit
This commit is contained in:
parent
377b65ae06
commit
f7d25f5c4c
54
bink.py
Normal file
54
bink.py
Normal file
@ -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())
|
Loading…
x
Reference in New Issue
Block a user