From 0fe9f21a6e97f762f1b236793db4f4b6d8c92f50 Mon Sep 17 00:00:00 2001 From: nebula Date: Tue, 13 May 2025 04:30:04 +0000 Subject: [PATCH] improve error handling --- bink.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/bink.py b/bink.py index 77ec5b8..a6b5537 100755 --- a/bink.py +++ b/bink.py @@ -50,22 +50,25 @@ def create_post(body): with open(f"{home}/{time_ns()}", "w", encoding="UTF-8") as f: f.write(body) -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] if not our else "our", path) - -def glob_posts(path): - return [ - file_object(post_path) for post_path in glob(path) - if os.path.isfile(post_path) and not os.path.islink(post_path) - ] +def glob_posts(path, our=False): + output = [] + for post_path in glob(path): + if not os.path.isfile(post_path): + continue + elif os.path.islink(post_path): + continue + split = post_path.split("/") + basename = split[-1] + 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): posts = glob_posts("/home/**/.bink/*") if our_path: - posts += glob_posts(f"{our_path}/*") + posts += glob_posts(f"{our_path}/*", our=True) for post in posts.copy(): if post[1] in filters: posts.remove(post)