-
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.
- Loading branch information
André Mourão
committed
Sep 23, 2020
1 parent
061f2fc
commit 47b0859
Showing
3 changed files
with
44 additions
and
8 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
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,25 @@ | ||
import csv | ||
import requests | ||
import re | ||
|
||
|
||
class MetaClassifierBlocked(): | ||
|
||
def __init__(self, block_list): | ||
download = requests.get(block_list) | ||
decoded_content = download.content.decode('utf-8') | ||
cr = csv.reader(decoded_content.splitlines(), delimiter=',') | ||
my_list = list(cr) | ||
self.regexes = [] | ||
for row in my_list: | ||
r = row[0] | ||
if r.endswith("/"): | ||
r = r[:-1] | ||
self.regexes.append(re.compile(r)) | ||
|
||
def classify(self, jsonline): | ||
for regex in self.regexes: | ||
if regex.search(jsonline['url']): | ||
jsonline['blocked'] = 1 | ||
return jsonline | ||
return jsonline |
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