add support for our
This commit is contained in:
parent
2f04636314
commit
0ecb1024a0
21
bink.py
21
bink.py
@ -9,6 +9,7 @@ import tempfile
|
|||||||
from math import floor
|
from math import floor
|
||||||
|
|
||||||
home = os.path.expanduser("~/.bink")
|
home = os.path.expanduser("~/.bink")
|
||||||
|
our_path = "/town/our/data/.bink"
|
||||||
filters = []
|
filters = []
|
||||||
filters_path = os.path.expanduser("~/.binkfilters")
|
filters_path = os.path.expanduser("~/.binkfilters")
|
||||||
max_body_length = 64_000
|
max_body_length = 64_000
|
||||||
@ -23,6 +24,11 @@ try:
|
|||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.mkdir(our_path)
|
||||||
|
except FileExistsError:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(filters_path, "r") as f:
|
with open(filters_path, "r") as f:
|
||||||
filters = json.load(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:
|
with open(f"{home}/{time_ns()}", "w", encoding="UTF-8") as f:
|
||||||
f.write(body)
|
f.write(body)
|
||||||
|
|
||||||
def file_object(path):
|
def file_object(path, our=False):
|
||||||
split = path.split("/")
|
split = path.split("/")
|
||||||
# example input: /home/nebula/.bink/999
|
# example input: /home/nebula/.bink/999
|
||||||
# output: (999, "nebula", "/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):
|
def generate_feed(before=None, count=200):
|
||||||
posts = [
|
posts = [
|
||||||
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)
|
||||||
]
|
]
|
||||||
|
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():
|
for post in posts.copy():
|
||||||
if post[1] in filters:
|
if post[1] in filters:
|
||||||
posts.remove(post)
|
posts.remove(post)
|
||||||
@ -71,14 +82,14 @@ def generate_feed(before=None, count=200):
|
|||||||
return blogs
|
return blogs
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
if sys.argv[1] == "--help" or sys.argv[1] == "-h":
|
if sys.argv[1] in ("--help", "-h"):
|
||||||
print(helptext)
|
print(helptext)
|
||||||
exit(0)
|
exit(0)
|
||||||
elif sys.argv[1] == "--dump":
|
elif sys.argv[1] in ("--dump", "-d"):
|
||||||
with open("/dev/stdout", "w") as f:
|
with open("/dev/stdout", "w") as f:
|
||||||
json.dump(generate_feed(), f)
|
json.dump(generate_feed(), f)
|
||||||
exit(0)
|
exit(0)
|
||||||
elif sys.argv[1] == "--pipe":
|
elif sys.argv[1] in ("--pipe", "-p"):
|
||||||
try:
|
try:
|
||||||
with open("/dev/stdin", "r", encoding="UTF-8") as f:
|
with open("/dev/stdin", "r", encoding="UTF-8") as f:
|
||||||
body = f.read().strip()
|
body = f.read().strip()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user