improve error handling

This commit is contained in:
nebula 2025-05-13 04:30:04 +00:00
parent ac27668621
commit 0fe9f21a6e

27
bink.py
View File

@ -50,22 +50,25 @@ def create_post(body):
with open(f"{home}/{time_ns()}", "w", encoding="UTF-8") as f: with open(f"{home}/{time_ns()}", "w", encoding="UTF-8") as f:
f.write(body) f.write(body)
def file_object(path, our=False): def glob_posts(path, our=False):
split = path.split("/") output = []
# example input: /home/nebula/.bink/999 for post_path in glob(path):
# output: (999, "nebula", "/home/nebula/.bink/999") if not os.path.isfile(post_path):
return (int(split[-1]), split[2] if not our else "our", path) continue
elif os.path.islink(post_path):
def glob_posts(path): continue
return [ split = post_path.split("/")
file_object(post_path) for post_path in glob(path) basename = split[-1]
if os.path.isfile(post_path) and not os.path.islink(post_path) try:
] output.append((int(basename), "our" if our else split[2], post_path))
except ValueError: # filename is not just numbers, cannot use int()
continue
return output
def generate_feed(before=None, after=None, count=200): def generate_feed(before=None, after=None, count=200):
posts = glob_posts("/home/**/.bink/*") posts = glob_posts("/home/**/.bink/*")
if our_path: if our_path:
posts += glob_posts(f"{our_path}/*") posts += glob_posts(f"{our_path}/*", our=True)
for post in posts.copy(): for post in posts.copy():
if post[1] in filters: if post[1] in filters:
posts.remove(post) posts.remove(post)