From: FrancoGag Date: Thu, 5 Nov 2015 13:44:42 +0000 (-0300) Subject: Exclude domains contained in a whitelist X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=461b06710c9530227249d6cd5b30278d4f881008;p=stevenblack-hosts.git Exclude domains contained in a whitelist --- diff --git a/updateHostsFile.py b/updateHostsFile.py index 484ccdb81..fc460aa1f 100755 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -77,10 +77,18 @@ SOURCES = listdir_nohidden(DATA_PATH) README_TEMPLATE = os.path.join(BASEDIR_PATH, 'readme_template.md') README_FILE = os.path.join(BASEDIR_PATH, 'readme.md') TARGET_HOST = '0.0.0.0' +WHITELIST_FILE = os.path.join(BASEDIR_PATH, 'whitelist') # Exclusions EXCLUSION_PATTERN = '([a-zA-Z\d-]+\.){0,}' #append domain the end +# Exclutions from whitelist file +EXCLUSIONS = [] +if os.path.isfile(WHITELIST_FILE): + with open(WHITELIST_FILE, "r") as ins: + for line in ins: + EXCLUSIONS.append(line) + # Common domains to exclude COMMON_EXCLUSIONS = ['hulu.com'] @@ -90,6 +98,7 @@ numberOfRules = 0 def main(): promptForUpdate() + excludeFromFile() promptForExclusions() mergeFile = createInitialFile() finalFile = removeDups(mergeFile) @@ -99,6 +108,14 @@ def main(): promptForMove(finalFile) +# Exclusion from file +def excludeFromFile(): + for domain in EXCLUSIONS: + if (domain != '' and not domain.startswith("#")): + domainRegex = re.compile("www\d{0,3}[.]|https?") + if not (domainRegex.match(domain)): + excludeDomain(domain) + # Prompt the User def promptForUpdate(): response = query_yes_no("Do you want to update all data sources?")