fix: load remote blocklist for export and fix diff with toml input

This commit is contained in:
moanos [he/him] 2023-12-19 10:19:24 +01:00
parent 0b37e7a10c
commit 1c2f65b433

View File

@ -12,12 +12,16 @@ from fediverse_blocklist_deploy.helpers import blocklist_to_markdown, blocklist_
def load_blocklist_file(filename: str) -> [Instance]: def load_blocklist_file(filename: str) -> [Instance]:
with open(filename, "r") as f: if filename.endswith("json"):
data = toml.load(f) with open(filename) as f:
instances = [] instances = blocklist_json_to_instances(json.load(f))
for instance_dict in data["instances"]: else:
instance = Instance(instance_dict) with open(filename, "r") as f:
instances.append(instance) data = toml.load(f)
instances = []
for instance_dict in data["instances"]:
instance = Instance(instance_dict)
instances.append(instance)
return instances return instances
@ -121,11 +125,10 @@ def cli():
token = os.getenv('MBD_TOKEN') token = os.getenv('MBD_TOKEN')
"""Get a remote blocklist only when necessary""" """Get a remote blocklist only when necessary"""
if args.action in ["diff", "deploy"]: if args.action in ["diff", "deploy", "export"]:
"""if there is a remote blocklist provided load this instead of fetching it from a server (for debugging reasons)""" """if there is a remote blocklist provided load this instead of fetching it from a server (for debugging reasons)"""
if args.remote_blocklist: if args.remote_blocklist:
with open(args.remote_blocklist) as f: remote_blocklist = load_blocklist_file(args.remote_blocklist)
remote_blocklist = blocklist_json_to_instances(json.load(f))
else: else:
remote_blocklist = load_blocklist_from_instance(server=args.server, token=token) remote_blocklist = load_blocklist_from_instance(server=args.server, token=token)