1
0
mirror of https://github.com/minoplhy/filters-maker.git synced 2025-02-23 16:54:52 +00:00
filters-maker/maker_domains.py

34 lines
1.2 KiB
Python
Raw Normal View History

2021-08-01 18:05:44 +07:00
import datetime
import pytz
UTC = pytz.utc
date = datetime.datetime.now(UTC)
def linecounter(incoming):
with open(incoming) as f:
2021-08-01 18:05:44 +07:00
for i, l in enumerate(f):
pass
return i + 1
2021-08-02 21:00:05 +07:00
def domainsbuilding(excluded ,incoming):
2021-08-02 22:17:07 +07:00
ankstanop = linecounter(incoming)
2021-08-01 18:05:44 +07:00
with open(excluded ,'r') as f:
exclude = f.read().split()
2021-08-02 21:00:05 +07:00
with open(incoming ,'r') as f:
2021-08-01 18:05:44 +07:00
lines = f.read().splitlines() # read lines
2021-08-02 21:00:05 +07:00
with open(incoming ,'w') as f:
2021-08-01 18:05:44 +07:00
f.write('# Title : Minoplhy Personal Blocklist\n')
f.write('# Description : My Very Personal DNS Blocklist plus crawling from the source\n')
2021-08-01 18:07:39 +07:00
f.write('# Source : Resources/Source.txt\n')
2021-08-02 08:20:43 -07:00
f.write('# Rule Counter : ' + str(ankstanop) +' Rules\n')
2021-08-01 18:05:44 +07:00
f.write('# Format : Domains\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('#'):
f.write('\n'.join([line + '\n']))
2021-08-02 08:31:07 -07:00
elif line.startswith((';','$','@',' IN')):
2021-08-01 18:05:44 +07:00
f.write('\n'.join([line + '\n']))
2021-08-02 08:31:07 -07:00
elif not line.strip():
2021-08-01 18:05:44 +07:00
f.write('\n'.join([line + '\n']))
f.close()