improve error handling
This commit is contained in:
parent
ac27668621
commit
0fe9f21a6e
27
bink.py
27
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user