diff --git a/sites/__init__.py b/sites/__init__.py index f83c2e3..b5e44b6 100644 --- a/sites/__init__.py +++ b/sites/__init__.py @@ -20,6 +20,8 @@ class Site: def _soup(self, url, method='html5lib'): page = self.fetch(url) + if not page: + raise SiteException("Couldn't fetch", url) return BeautifulSoup(page, method) class SiteException(Exception): @@ -35,4 +37,4 @@ def get(url): return site_class # And now, the things that will use this: -from . import spacebattles, fanfictionnet, deviantart, stash +from . import xenforo, fanfictionnet, deviantart, stash diff --git a/sites/spacebattles.py b/sites/xenforo.py similarity index 78% rename from sites/spacebattles.py rename to sites/xenforo.py index d1da52a..6a96679 100644 --- a/sites/spacebattles.py +++ b/sites/xenforo.py @@ -4,13 +4,14 @@ import re from . import register, Site, SiteException -@register -class SpaceBattles(Site): - """SpaceBattles is a forum...""" +class XenForo(Site): + """XenForo is forum software that powers a number of fiction-related forums.""" - @staticmethod - def matches(url): - return re.match(r'^https?://forums.(?:spacebattles|sufficientvelocity).com/threads/.*\d+/?.*', url) + domain = False + + @classmethod + def matches(cls, url): + return re.match(r'^https?://%s/threads/.*\d+/?.*' % cls.domain, url) def extract(self, url): soup = self._soup(url) @@ -101,12 +102,35 @@ class SpaceBattles(Site): return post.prettify() -@register -class SpaceBattlesIndex(SpaceBattles): - """A spacebattles thread with an index post""" - @staticmethod - def matches(url): - return re.match(r'^https?://forums.(?:spacebattles|sufficientvelocity).com/posts/\d+/?.*', url) +class XenForoIndex(XenForo): + @classmethod + def matches(cls, url): + return re.match(r'^https?://%s/posts/\d+/?.*' % cls.domain, url) def _chapter_list(self, url): return self._chapter_list_index(url) + + +@register +class SpaceBattles(XenForo): + domain = 'forums.spacebattles.com' + + +@register +class SpaceBattlesIndex(XenForoIndex): + domain = 'forums.spacebattles.com' + + +@register +class SufficientVelocity(XenForo): + domain = 'forums.sufficientvelocity.com' + + +@register +class QuestionableQuesting(XenForo): + domain = 'forum.questionablequesting.com' + + +@register +class QuestionableQuestingIndex(QuestionableQuesting, XenForoIndex): + pass