forked from easylist/EasyListHebrew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneralFinder.py
40 lines (33 loc) · 1.05 KB
/
generalFinder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import sys
import re
class Filter(object):
def __init__(self,fil,typ,domain):
self.filter=fil
self.typ=typ
self.domain=domain
def __str__(self):
return ','.join(sorted(self.domain))+self.typ+self.filter
regex=re.compile(r"^([a-zA-Z0-9-.]+)(#{2}[#.]?)(.*)",re.MULTILINE)
regex2=re.compile(r"^([a-zA-Z0-9-.]+[,][a-zA-Z0-9-.,]+)(#{2}[#.]?)(.*)",re.MULTILINE)
with open ('EasyListHebrew.txt') as f:
l=f.read()
one= regex.findall(l)
general= regex2.findall(l)
dic_res={}
for lst in general:
dic_res[lst[1]+lst[2]]=Filter(lst[2],lst[1], lst[0].split(','))
for lst in one:
key=lst[1]+lst[2]
if key in dic_res:
dic_res[key].domain.append(lst[0])
else:
dic_res[key]=Filter(lst[2],lst[1], [lst[0],])
#print all keys with the same vlas
sor=sorted([x for x in dic_res.values() if len(x.domain)>1],key=lambda x:x.typ + x.filter)
for val in sor:
print val
print '\nfilters to delete:'
filters=[(x.typ,x.filter) for x in sor]
for o in one:
if (o[1],o[2]) in filters:
print ''.join(o)