INNER CODE UNIT · Python

download_or_read_domains

blokadaorg/blokada · scripts/convert-domains-to-rules.py:15

def download_or_read_domains(source):
    """Download domains from URL or read from local file."""
    parsed = urlparse(source)

    if parsed.scheme in ('http', 'https'):
        print(f"Downloading domains from {source}...")
        try:
            with urllib.request.urlopen(source) as response:
                content = response.read().decode('utf-8')
            return content
        except Exception as e:
            print(f"Error downloading from {source}: {e}")
            sys.exit(1)
    else:
        # Treat as local file
        print(f"Reading domains from {source}...")
        try:
            with open(source, 'r', encoding='utf-8') as f:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…