Skip to content

Commit

Permalink
- Automatically recognizing class name as key for metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertMeissner committed Nov 9, 2020
1 parent b8608a2 commit 10c8887
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 29 deletions.
28 changes: 5 additions & 23 deletions src/features/html_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class Advertisement(MetadataBase):
"https://easylist.to/easylist/easylist_thirdparty.txt",
"https://easylist.to/easylist/easylist_thirdparty_popup.txt",
]
key: str = "ads"


class EasyPrivacy(MetadataBase):
Expand All @@ -36,7 +35,6 @@ class EasyPrivacy(MetadataBase):
"https://github.com/easylist/easylist/blob/master/easyprivacy/easyprivacy_thirdparty.txt",
"https://github.com/easylist/easylist/blob/master/easyprivacy/easyprivacy_thirdparty_international.txt",
]
key = "easyprivacy"


class IETracker(MetadataBase):
Expand All @@ -58,7 +56,6 @@ class Cookies(MetadataBase):
"https://github.com/easylist/easylist/blob/master/easylist_cookie/easylist_cookie_specific_hide.txt",
"https://github.com/easylist/easylist/blob/master/easylist_cookie/easylist_cookie_thirdparty.txt",
]
key: str = "cookies"


class FanboyAnnoyance(MetadataBase):
Expand All @@ -72,7 +69,6 @@ class FanboyAnnoyance(MetadataBase):
"https://easylist.to/easylist/fanboy_annoyance_specific_block.txt",
"https://easylist.to/easylist/fanboy_annoyance_thirdparty.txt",
]
key: str = "fanboy_annoyance"


class FanboyNotification(MetadataBase):
Expand All @@ -85,7 +81,6 @@ class FanboyNotification(MetadataBase):
"https://easylist.to/easylist/fanboy_notifications_specific_hide.txt",
"https://easylist.to/easylist/fanboy_notifications_thirdparty.txt",
]
key: str = "fanboy_notification"


class FanboySocialMedia(MetadataBase):
Expand All @@ -100,26 +95,17 @@ class FanboySocialMedia(MetadataBase):
"https://easylist.to/easylist/fanboy_social_specific_hide.txt",
"https://easylist.to/easylist/fanboy_social_thirdparty.txt",
]
key: str = "fanboy_social"


class AntiAdBlock(MetadataBase):
url: str = (
"https://easylist-downloads.adblockplus.org/antiadblockfilters.txt"
)
urls: list = [
"https://easylist-downloads.adblockplus.org/antiadblockfilters.txt",
"https://github.com/easylist/antiadblockfilters/blob/master/antiadblockfilters/antiadblock_german.txt",
"https://github.com/easylist/antiadblockfilters/blob/master/antiadblockfilters/antiadblock_english.txt",
]
key: str = "anti_adblock"


class AntiAdBlockGerman(MetadataBase):
url: str = "https://github.com/easylist/antiadblockfilters/blob/master/antiadblockfilters/antiadblock_german.txt"
key: str = "antiadblock_german"


class AntiAdBlockEnglish(MetadataBase):
url: str = "https://github.com/easylist/antiadblockfilters/blob/master/antiadblockfilters/antiadblock_english.txt"
key: str = "antiadblock_english"


class EasylistGermany(MetadataBase):
urls: list = [
"https://easylist.to/easylistgermany/easylistgermany.txt",
Expand All @@ -138,7 +124,6 @@ class EasylistGermany(MetadataBase):
"https://github.com/easylist/easylistgermany/blob/master/easylistgermany/easylistgermany_thirdparty.txt",
"https://github.com/easylist/easylistgermany/blob/master/easylistgermany/easylistgermany_thirdparty_popup.txt",
]
key: str = "easylist_germany"


class EasylistAdult(MetadataBase):
Expand All @@ -153,7 +138,6 @@ class EasylistAdult(MetadataBase):
"https://github.com/easylist/easylist/blob/master/easylist_adult/adult_thirdparty.txt",
"https://github.com/easylist/easylist/blob/master/easylist_adult/adult_thirdparty_popup.txt",
]
key: str = "easylist_adult"


class Paywalls(MetadataBase):
Expand All @@ -163,7 +147,6 @@ class Paywalls(MetadataBase):

class ContentSecurityPolicy(MetadataBase):
tag_list = ["Content-Security-Policy"]
key: str = "content_security_policy"
evaluate_header = True


Expand All @@ -183,4 +166,3 @@ class PopUp(MetadataBase):
"interstitial",
"Interstitial",
]
key = "popup"
5 changes: 5 additions & 0 deletions src/features/metadata_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class MetadataBase:
def __init__(self, logger) -> None:
self._logger = logger

if self.key == "":
self.key = re.sub(
r"(?<!^)(?=[A-Z])", "_", self.__class__.__name__
).lower()

def start(self, html_content: str = "", header=None) -> dict:
if header is None:
header = {}
Expand Down
4 changes: 0 additions & 4 deletions src/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
from features.html_based import (
Advertisement,
AntiAdBlock,
AntiAdBlockEnglish,
AntiAdBlockGerman,
ContentSecurityPolicy,
Cookies,
EasylistAdult,
Expand Down Expand Up @@ -79,8 +77,6 @@ def _create_extractors(self):
FanboyNotification,
FanboySocialMedia,
AntiAdBlock,
AntiAdBlockGerman,
AntiAdBlockEnglish,
EasylistGermany,
EasylistAdult,
Paywalls,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/manager_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_init(manager: Manager, mocker):
assert manager._create_logger.call_count == 1
assert manager._create_api.call_count == 1
assert run_spy.call_count == 0
assert len(manager.metadata_extractors) == 17
assert len(manager.metadata_extractors) == 15
assert manager.run_loop


Expand Down
2 changes: 1 addition & 1 deletion tests/unit/metadatabase_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_init(metadatabase: MetadataBase, mocker):
assert metadatabase.tag_list == []
assert metadatabase.tag_list_last_modified == ""
assert metadatabase.tag_list_expires == 0
assert metadatabase.key == ""
assert metadatabase.key == "metadata_base"
assert metadatabase.url == ""
assert metadatabase.comment_symbol == ""
assert not metadatabase.evaluate_header
Expand Down

0 comments on commit 10c8887

Please sign in to comment.