From e78ffdb85bd7d0b3a7072feadd635c4e2168c734 Mon Sep 17 00:00:00 2001 From: David Lynch Date: Thu, 11 Oct 2018 15:42:59 -0500 Subject: [PATCH] Method to get a site-key for config Means that things like XenForoIndex and AO3Series don't require separate config entries. --- leech.py | 4 ++-- sites/__init__.py | 8 +++++++- sites/ao3.py | 2 ++ sites/xenforo.py | 6 +++--- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/leech.py b/leech.py index e4314eb..e068fa5 100755 --- a/leech.py +++ b/leech.py @@ -54,8 +54,8 @@ def load_on_disk_options(site): try: with open('leech.json') as store_file: store = json.load(store_file) - login = store.get('logins', {}).get(site.__name__, False) - configured_site_options = store.get('site_options', {}).get(site.__name__, {}) + login = store.get('logins', {}).get(site.site_key(), False) + configured_site_options = store.get('site_options', {}).get(site.site_key(), {}) cover_options = store.get('cover', {}) except FileNotFoundError: logger.info("Unable to locate leech.json. Continuing assuming it does not exist.") diff --git a/sites/__init__.py b/sites/__init__.py index 313496f..388b8a9 100644 --- a/sites/__init__.py +++ b/sites/__init__.py @@ -67,12 +67,18 @@ class Site: extracting the content of a story from said site. """ session = attr.ib() - footnotes = attr.ib(default=attr.Factory(list), init=False) + footnotes = attr.ib(factory=list, init=False) options = attr.ib(default=attr.Factory( lambda site: site.get_default_options(), True )) + @classmethod + def site_key(cls): + if hasattr(cls, '_key'): + return cls._key + return cls.__name__ + @staticmethod def get_site_specific_option_defs(): """Returns a list of click.option objects to add to CLI commands. diff --git a/sites/ao3.py b/sites/ao3.py index 27ae4d0..b3ab51f 100644 --- a/sites/ao3.py +++ b/sites/ao3.py @@ -89,6 +89,8 @@ class ArchiveOfOurOwn(Site): @register class ArchiveOfOurOwnSeries(ArchiveOfOurOwn): + _key = "ArchiveOfOurOwn" + @staticmethod def matches(url): # e.g. http://archiveofourown.org/series/5683105/ diff --git a/sites/xenforo.py b/sites/xenforo.py index 749969e..39b8bae 100644 --- a/sites/xenforo.py +++ b/sites/xenforo.py @@ -249,7 +249,7 @@ class SpaceBattles(XenForo): @register class SpaceBattlesIndex(SpaceBattles, XenForoIndex): - pass + _key = "SpaceBattles" @register @@ -264,7 +264,7 @@ class QuestionableQuesting(XenForo): @register class QuestionableQuestingIndex(QuestionableQuesting, XenForoIndex): - pass + _key = "QuestionableQuesting" @register @@ -274,4 +274,4 @@ class AlternateHistory(XenForo): @register class AlternateHistoryIndex(AlternateHistory, XenForoIndex): - pass + _key = "AlternateHistory"