1
0
Fork 0
mirror of https://github.com/kemayo/leech synced 2026-02-14 10:42:41 +01:00

Method to get a site-key for config

Means that things like XenForoIndex and AO3Series don't require separate
config entries.
This commit is contained in:
David Lynch 2018-10-11 15:42:59 -05:00
parent cdcd110c50
commit e78ffdb85b
4 changed files with 14 additions and 6 deletions

View file

@ -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.")

View file

@ -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.

View file

@ -89,6 +89,8 @@ class ArchiveOfOurOwn(Site):
@register
class ArchiveOfOurOwnSeries(ArchiveOfOurOwn):
_key = "ArchiveOfOurOwn"
@staticmethod
def matches(url):
# e.g. http://archiveofourown.org/series/5683105/

View file

@ -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"