forked from AICP/vendor_aicp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vendor/aicp: Toggle-able adblock hosts file [2/3]
Regenerate with ./adaway/generate.sh Change-Id: Ia389457746f9af1060a1c1ae62af0cb9ca643a71
- Loading branch information
1 parent
8161296
commit 9867edd
Showing
6 changed files
with
15,321 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from datetime import datetime | ||
import sys | ||
|
||
def write_header(f, sources): | ||
f.write("# This hosts file has been generated on:\n# {}\n# This file is generated from the following sources:\n".format(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))) | ||
for s in sources: | ||
f.write("# {}\n".format(s)) | ||
f.write("\n127.0.0.1 localhost\n::1 localhost\n\n") | ||
|
||
def read_redirect(line): | ||
source = None | ||
target = None | ||
for l in line.split(" "): | ||
if l.startswith("#"): | ||
# Ignore comments | ||
return None | ||
if len(l) > 0: | ||
if source == None: | ||
source = l | ||
else: | ||
target = l | ||
return (source, target) | ||
return None | ||
|
||
if __name__ == "__main__": | ||
source_dir = sys.argv[1] | ||
outfile = sys.argv[2] | ||
sources = sys.argv[3:] | ||
redirects = [] | ||
source_urls = [] | ||
with open("{}/sources.txt".format(source_dir), "r") as fin: | ||
for line in fin: | ||
line = line.split("\n")[0] | ||
if len(line) > 0: | ||
source_urls.append(line) | ||
with open(outfile, 'w') as fout: | ||
write_header(fout, source_urls) | ||
# Read hosts sources | ||
for infile in sources: | ||
with open(infile, 'r') as fin: | ||
for line in fin: | ||
line = line.split('\n')[0] | ||
redirect = read_redirect(line) | ||
if redirect != None: | ||
redirects.append(redirect) | ||
# Remove duplicates and sort it | ||
redirects = sorted(list(set(redirects))) | ||
# Write it | ||
for redirect in redirects: | ||
if redirect[1] == "localhost": | ||
continue | ||
fout.write("127.0.0.1 {}\n".format(redirect[1])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
mydir="$(dirname "$(realpath "$0")")" | ||
|
||
hosts_dir="$mydir/.hosts/" | ||
hosts_out="$mydir/../prebuilt/common/etc/hosts.aicp_adblock" | ||
|
||
download_hosts() { | ||
url="$1" | ||
outfile="$2" | ||
wget "$url" -O "$outfile" | ||
} | ||
|
||
|
||
rm "$hosts_dir"/* | ||
|
||
i=0 | ||
|
||
while read l; do | ||
((i++)) | ||
download_hosts "$l" "$hosts_dir/hosts$i.txt" | ||
done < "$mydir/sources.txt" | ||
|
||
python3 "$mydir/generate.py" "$mydir" "$hosts_out" "$hosts_dir"/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
https://adaway.org/hosts.txt | ||
https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.