add support for our

This commit is contained in:
nebula 2025-04-30 23:36:50 +00:00
parent 2f04636314
commit 0ecb1024a0

21
bink.py
View File

@ -9,6 +9,7 @@ import tempfile
from math import floor
home = os.path.expanduser("~/.bink")
our_path = "/town/our/data/.bink"
filters = []
filters_path = os.path.expanduser("~/.binkfilters")
max_body_length = 64_000
@ -23,6 +24,11 @@ try:
except FileExistsError:
pass
try:
os.mkdir(our_path)
except FileExistsError:
pass
try:
with open(filters_path, "r") as f:
filters = json.load(f)
@ -39,17 +45,22 @@ def create_post(body):
with open(f"{home}/{time_ns()}", "w", encoding="UTF-8") as f:
f.write(body)
def file_object(path):
def file_object(path, our=False):
split = path.split("/")
# example input: /home/nebula/.bink/999
# output: (999, "nebula", "/home/nebula/.bink/999")
return (int(split[-1]), split[2], path)
return (int(split[-1]), split[2] if not our else "our", path)
def generate_feed(before=None, count=200):
posts = [
file_object(path) for path in glob("/home/**/.bink/*")
if os.path.isfile(path) and not os.path.islink(path)
]
our = [
file_object(path, our=True) for path in glob(f"{our_path}/*")
if os.path.isfile(path) and not os.path.islink(path)
]
posts += our
for post in posts.copy():
if post[1] in filters:
posts.remove(post)
@ -71,14 +82,14 @@ def generate_feed(before=None, count=200):
return blogs
if len(sys.argv) > 1:
if sys.argv[1] == "--help" or sys.argv[1] == "-h":
if sys.argv[1] in ("--help", "-h"):
print(helptext)
exit(0)
elif sys.argv[1] == "--dump":
elif sys.argv[1] in ("--dump", "-d"):
with open("/dev/stdout", "w") as f:
json.dump(generate_feed(), f)
exit(0)
elif sys.argv[1] == "--pipe":
elif sys.argv[1] in ("--pipe", "-p"):
try:
with open("/dev/stdin", "r", encoding="UTF-8") as f:
body = f.read().strip()