fix: load remote blocklist for export and fix diff with toml input
This commit is contained in:
		@@ -12,12 +12,16 @@ from fediverse_blocklist_deploy.helpers import blocklist_to_markdown, blocklist_
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def load_blocklist_file(filename: str) -> [Instance]:
 | 
			
		||||
    with open(filename, "r") as f:
 | 
			
		||||
        data = toml.load(f)
 | 
			
		||||
    instances = []
 | 
			
		||||
    for instance_dict in data["instances"]:
 | 
			
		||||
        instance = Instance(instance_dict)
 | 
			
		||||
        instances.append(instance)
 | 
			
		||||
    if filename.endswith("json"):
 | 
			
		||||
        with open(filename) as f:
 | 
			
		||||
            instances = blocklist_json_to_instances(json.load(f))
 | 
			
		||||
    else:
 | 
			
		||||
        with open(filename, "r") as f:
 | 
			
		||||
            data = toml.load(f)
 | 
			
		||||
        instances = []
 | 
			
		||||
        for instance_dict in data["instances"]:
 | 
			
		||||
            instance = Instance(instance_dict)
 | 
			
		||||
            instances.append(instance)
 | 
			
		||||
    return instances
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -121,11 +125,10 @@ def cli():
 | 
			
		||||
        token = os.getenv('MBD_TOKEN')
 | 
			
		||||
 | 
			
		||||
    """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 args.remote_blocklist:
 | 
			
		||||
            with open(args.remote_blocklist) as f:
 | 
			
		||||
                remote_blocklist = blocklist_json_to_instances(json.load(f))
 | 
			
		||||
            remote_blocklist = load_blocklist_file(args.remote_blocklist)
 | 
			
		||||
        else:
 | 
			
		||||
            remote_blocklist = load_blocklist_from_instance(server=args.server, token=token)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user