Wsparcie dla formatu uBlacklist #5

Open
wiktor wants to merge 9 commits from ublacklist-format into master
12 changed files with 47 additions and 5 deletions

View File

@ -1,10 +1,12 @@
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
build: dist/seo-nonsense/adguard.txt
build: $(foreach blocklist, $(BLOCKLISTS), $(foreach targetformat, $(TARGET_FORMATS), dist/$(blocklist)/$(targetformat).txt))
dist/%.txt:
@mkdir -p $(dir $@) && \
$(CONVERTER) --inputfile src/$(firstword $(subst /, ,$*))-source.json --targetformat $(notdir $*) --outputfile $@
clean:
rm -rf dist/*

2
dist/mirror/adguard.txt vendored Normal file
View File

@ -0,0 +1,2 @@
! Blocking list automatically generated at 2025-05-25 19:55:20 UTC+0000
! Created with ❤️ by internet-czas-dzialac.pl

2
dist/mirror/ublacklist.txt vendored Normal file
View File

@ -0,0 +1,2 @@
# Blocking list automatically generated at 2025-05-25 19:55:20 UTC+0000
# Created with ❤️ by internet-czas-dzialac.pl

2
dist/reflink-spam/adguard.txt vendored Normal file
View File

@ -0,0 +1,2 @@
! Blocking list automatically generated at 2025-05-25 19:55:22 UTC+0000
! Created with ❤️ by internet-czas-dzialac.pl

2
dist/reflink-spam/ublacklist.txt vendored Normal file
View File

@ -0,0 +1,2 @@
# Blocking list automatically generated at 2025-05-25 19:55:22 UTC+0000
# Created with ❤️ by internet-czas-dzialac.pl

2
dist/satire/adguard.txt vendored Normal file
View File

@ -0,0 +1,2 @@
! Blocking list automatically generated at 2025-05-25 19:55:24 UTC+0000
! Created with ❤️ by internet-czas-dzialac.pl

2
dist/satire/ublacklist.txt vendored Normal file
View File

@ -0,0 +1,2 @@
# Blocking list automatically generated at 2025-05-25 19:55:24 UTC+0000
# Created with ❤️ by internet-czas-dzialac.pl

View File

@ -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)

3
src/mirror-source.json Normal file
View File

@ -0,0 +1,3 @@
{
"domains": []
}

View File

@ -0,0 +1,3 @@
{
"domains": []
}

3
src/satire-source.json Normal file
View File

@ -0,0 +1,3 @@
{
"domains": []
}