add support for filtering by user

This commit is contained in:
nebula 2025-04-26 20:58:53 +00:00
parent 35621f169f
commit b9ba6ef0d7

11
bink.py
View File

@ -9,6 +9,8 @@ import tempfile
from math import floor from math import floor
home = os.path.expanduser("~/.bink") home = os.path.expanduser("~/.bink")
filters = []
filters_path = f"{home}/.binkfilters"
max_body_length = 64_000 max_body_length = 64_000
helptext = """see https://git.tilde.town/nebula/bink for details helptext = """see https://git.tilde.town/nebula/bink for details
@ -21,6 +23,12 @@ try:
except FileExistsError: except FileExistsError:
pass pass
try:
with open(filters_path, "r") as f:
filters = json.load(f.read())
except FileNotFoundError:
pass
try: try:
editor = os.environ["EDITOR"] editor = os.environ["EDITOR"]
except KeyError: except KeyError:
@ -41,6 +49,9 @@ def generate_feed(before=None, count=200):
file_object(path) for path in glob("/home/**/.bink/*") file_object(path) for path in glob("/home/**/.bink/*")
if os.path.isfile(path) and not os.path.islink(path) if os.path.isfile(path) and not os.path.islink(path)
] ]
for post in posts.copy():
if post[1] in filters:
posts.remove(post)
if before: if before:
posts = [post for post in posts if post[0] < before] posts = [post for post in posts if post[0] < before]
posts.sort(key=lambda x: x[0], reverse=True) posts.sort(key=lambda x: x[0], reverse=True)