diff --git a/Makefile b/Makefile index d934435..ea5f65e 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,23 @@ CONVERTER = python3 src/converter.py +BLOCKLISTS = seo-nonsense reflink-spam satire mirror +TARGET_FORMATS = adguard ublacklist -dist/seo-nonsense/adguard.txt:: src/seo-source.json - $(CONVERTER) --inputfile src/seo-source.json --targetformat adguard --outputfile dist/seo-nonsense/adguard.txt +TARGETS = $(foreach blocklist, $(BLOCKLISTS), $(foreach targetformat, $(TARGET_FORMATS), dist/$(blocklist)/$(targetformat).txt)) -build: dist/seo-nonsense/adguard.txt +build: $(TARGETS) +dist/%/adguard.txt: src/%-source.json + mkdir -p dist/$* + $(CONVERTER) --inputfile src/$*-source.json --targetformat adguard --outputfile $@ + +dist/%/ublacklist.txt: src/%-source.json + mkdir -p dist/$* + $(CONVERTER) --inputfile src/$*-source.json --targetformat ublacklist --outputfile $@ clean: rm -rf dist/* all: build + +.PHONY: build clean all + diff --git a/dist/mirror/adguard.txt b/dist/mirror/adguard.txt new file mode 100644 index 0000000..9079baf --- /dev/null +++ b/dist/mirror/adguard.txt @@ -0,0 +1,2 @@ +! Blocking list automatically generated at 2025-05-25 19:55:20 UTC+0000 +! Created with ❤️ by internet-czas-dzialac.pl \ No newline at end of file diff --git a/dist/mirror/ublacklist.txt b/dist/mirror/ublacklist.txt new file mode 100644 index 0000000..486173d --- /dev/null +++ b/dist/mirror/ublacklist.txt @@ -0,0 +1,2 @@ +# Blocking list automatically generated at 2025-05-25 19:55:20 UTC+0000 +# Created with ❤️ by internet-czas-dzialac.pl \ No newline at end of file diff --git a/dist/reflink-spam/adguard.txt b/dist/reflink-spam/adguard.txt new file mode 100644 index 0000000..797a4dc --- /dev/null +++ b/dist/reflink-spam/adguard.txt @@ -0,0 +1,2 @@ +! Blocking list automatically generated at 2025-05-25 19:55:22 UTC+0000 +! Created with ❤️ by internet-czas-dzialac.pl \ No newline at end of file diff --git a/dist/reflink-spam/ublacklist.txt b/dist/reflink-spam/ublacklist.txt new file mode 100644 index 0000000..7cc2bcf --- /dev/null +++ b/dist/reflink-spam/ublacklist.txt @@ -0,0 +1,2 @@ +# Blocking list automatically generated at 2025-05-25 19:55:22 UTC+0000 +# Created with ❤️ by internet-czas-dzialac.pl \ No newline at end of file diff --git a/dist/satire/adguard.txt b/dist/satire/adguard.txt new file mode 100644 index 0000000..157c4c5 --- /dev/null +++ b/dist/satire/adguard.txt @@ -0,0 +1,2 @@ +! Blocking list automatically generated at 2025-05-25 19:55:24 UTC+0000 +! Created with ❤️ by internet-czas-dzialac.pl \ No newline at end of file diff --git a/dist/satire/ublacklist.txt b/dist/satire/ublacklist.txt new file mode 100644 index 0000000..a35e5e0 --- /dev/null +++ b/dist/satire/ublacklist.txt @@ -0,0 +1,2 @@ +# Blocking list automatically generated at 2025-05-25 19:55:24 UTC+0000 +# Created with ❤️ by internet-czas-dzialac.pl \ No newline at end of file diff --git a/src/converter.py b/src/converter.py index e10fb0c..b45b673 100644 --- a/src/converter.py +++ b/src/converter.py @@ -52,7 +52,7 @@ def parse_arguments() -> argparse.Namespace: "--targetformat", required=True, metavar="TARGET_FORMAT", - help="Target output format (e.g., adguard)", + help="Target output format (supported formats: adguard, ublacklist)", ) parser.add_argument( "--outputfile", @@ -76,6 +76,8 @@ def convert(data: dict, last_modified: datetime, target_format: str) -> str: match target_format: case "adguard": return adguard_conversion(last_modified, data) + case "ublacklist": + return ublacklist_conversion(last_modified, data) case _: raise UnsupportedTargetFormatError @@ -97,6 +99,23 @@ def adguard_conversion(last_modified: datetime, data: dict) -> list[str]: return "\n".join(output) +def ublacklist_conversion(last_modified: datetime, data: dict) -> list[str]: + header_lines: list[str] = [ + f"# Blocking list automatically generated at {last_modified.strftime('%Y-%m-%d %H:%M:%S %Z%z')}", + "# Created with ❤️ by internet-czas-dzialac.pl", + ] + + output: list[str] = list(header_lines) + + for entry in data["domains"]: + fqdn = entry["fqdn"] + if entry.get("exclude", False): + continue + output.append(f"*://*.{fqdn}/*") + + return "\n".join(output) + + def dump_output(data: str, output_file: str) -> None: try: directory = os.path.dirname(output_file) diff --git a/src/mirror-source.json b/src/mirror-source.json new file mode 100644 index 0000000..1240f0f --- /dev/null +++ b/src/mirror-source.json @@ -0,0 +1,3 @@ +{ + "domains": [] +} \ No newline at end of file diff --git a/src/reflink-spam-source.json b/src/reflink-spam-source.json new file mode 100644 index 0000000..1240f0f --- /dev/null +++ b/src/reflink-spam-source.json @@ -0,0 +1,3 @@ +{ + "domains": [] +} \ No newline at end of file diff --git a/src/satire-source.json b/src/satire-source.json new file mode 100644 index 0000000..1240f0f --- /dev/null +++ b/src/satire-source.json @@ -0,0 +1,3 @@ +{ + "domains": [] +} \ No newline at end of file diff --git a/src/seo-source.json b/src/seo-nonsense-source.json similarity index 100% rename from src/seo-source.json rename to src/seo-nonsense-source.json