This commit is contained in:
moanos [he/him] 2023-01-13 08:12:35 +01:00
commit 33fee03059

View File

@ -19,23 +19,6 @@ def load_blocklist_file(filename: str) -> [Instance]:
return instances
def export_blocklist_toml(blocklist: [Instance], filname: str):
toml_str = ""
for instance in blocklist:
toml_str += f'''
[[instances]]
name = "{instance.domain}"
domain = "{instance.domain}"
severity = "{instance.severity}"
reject_media = {str(instance.reject_media).lower()}
reject_reports = {str(instance.reject_reports).lower()}
public_comment = "{instance.public_comment}"
private_comment = "{instance.private_comment}"
'''
with open(filname, "w") as f:
f.write(toml_str)
def blocklist_json_to_instances(blocklist_json: str) -> [Instance]:
instances = []
for i in blocklist_json:
@ -109,9 +92,10 @@ def cli():
Instance.apply_blocks_from_diff(diffs, args.server, token, args.no_delete)
elif args.action == "export":
if not args.output:
print("Export currently requires to pass --output as well")
print(toml.dumps({"instances": [b.__dict__ for b in remote_blocklist]}))
else:
export_blocklist_toml(remote_blocklist, args.output)
with open(args.output, "w") as f:
toml.dump({"instances": [b.__dict__ for b in remote_blocklist]}, f)
if __name__ == "__main__":