filters-maker/maker_dnsmasq.py

36 lines
1.3 KiB
Python
Raw Normal View History

2021-09-29 15:06:42 +00:00
import datetime
import pytz
UTC = pytz.utc
date = datetime.datetime.now(UTC)
def linecounter(incoming):
with open(incoming) as f:
for i, l in enumerate(f):
pass
return i + 1
2021-09-29 15:45:33 +00:00
def DNQbuilding(excluded,incoming,output,Version):
2021-09-29 15:06:42 +00:00
ankstanop = linecounter(incoming)
with open(excluded ,'r') as f:
exclude = f.read().split()
with open(incoming ,'r') as f:
lines = f.read().splitlines() # read lines
2021-09-29 15:45:33 +00:00
with open(output ,'w') as f:
2021-09-29 15:06:42 +00:00
f.write('# Title : Minoplhy Personal Blocklist\n')
f.write('# Description : My Very Personal DNS Blocklist plus crawling from the source\n')
f.write('# Source : Resources/Source.txt\n')
f.write('# Rule Counter : ' + str(ankstanop) +' Rules\n')
2021-09-29 15:10:01 +00:00
f.write('# Format : Dnsmasq\n')
2021-09-29 15:06:42 +00:00
f.write('# Type : Blocklist\n')
f.write('# Version : ' + str(Version) +'\n')
f.write('# Licenses : MIT\n')
f.write('# Compiled Date : ' + str(date) +'\n\n')
for line in lines:
if line.strip() and not line in exclude and not line.startswith('#'):
2021-09-29 15:10:01 +00:00
f.write('\n'.join(['server=/' + line + '/\n']))
2021-09-29 15:06:42 +00:00
elif line.startswith((';','$','@',' IN')):
f.write('\n'.join([line + '\n']))
elif not line.strip():
f.write('\n'.join([line + '\n']))
f.close()