Files
pihole-blocklist/combine_lists.py

50 lines
1.3 KiB
Python

import os
from datetime import datetime
combined_list = []
combined_count = 0
expanded_list = []
expanded_count = 0
blocklists = [f for f in os.listdir("partials")]
for blocklist in blocklists:
count = 0
templist = []
f = open("partials/" + blocklist, "r")
for line in f:
line = line.replace("\n", "").replace("\r", "")
if line.count(".") == 1:
expanded_list.append("www." + line)
expanded_count += 1
templist.append(line)
count += 1
templist.sort()
combined_list.append("# [" + blocklist[:-4] + "]" + " - " + str(count))
combined_list += templist
combined_list.append("")
combined_count += count
full_list = [
"# Host file to block ads, tracking, etc.",
"# Title: Marvins Blacklist",
"# Expires: 1 days",
"# Hosts contributed by Marvin Scham <dev@marvinscham.de>",
"# Domains: "
+ str(combined_count + expanded_count)
+ " ("
+ str(combined_count)
+ " unique)",
"# Last Update: " + datetime.today().strftime("%Y-%m-%d"),
"# ======================================================",
"\n",
]
full_list += combined_list
full_list.append("# [Expanded] - " + str(expanded_count))
expanded_list.sort()
full_list += expanded_list
with open("adlist.txt", "w") as outfile:
outfile.write("\n".join(str(item) for item in full_list))