diff --git a/fanficfare/adapters/__init__.py b/fanficfare/adapters/__init__.py index ac80450e..74315c59 100644 --- a/fanficfare/adapters/__init__.py +++ b/fanficfare/adapters/__init__.py @@ -110,6 +110,7 @@ from . import adapter_tgstorytimecom from . import adapter_itcouldhappennet from . import adapter_forumsspacebattlescom from . import adapter_forumssufficientvelocitycom +from . import adapter_xf2testsufficientvelocitycom from . import adapter_forumquestionablequestingcom from . import adapter_ninelivesarchivecom from . import adapter_masseffect2in diff --git a/fanficfare/adapters/adapter_xf2testsufficientvelocitycom.py b/fanficfare/adapters/adapter_xf2testsufficientvelocitycom.py new file mode 100644 index 00000000..6610843f --- /dev/null +++ b/fanficfare/adapters/adapter_xf2testsufficientvelocitycom.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- + +# Copyright 2019 FanFicFare team +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from __future__ import absolute_import +import re + +from .base_xenforo2forum_adapter import BaseXenForo2ForumAdapter + +def getClass(): + return XF2TestSufficientVelocityComAdapter + +class XF2TestSufficientVelocityComAdapter(BaseXenForo2ForumAdapter): + + def __init__(self, config, url): + BaseXenForo2ForumAdapter.__init__(self, config, url) + + # Each adapter needs to have a unique site abbreviation. + self.story.setMetadata('siteabbrev','fsv2') + + @staticmethod # must be @staticmethod, don't remove it. + def getSiteDomain(): + # The site domain. Does have www here, if it uses it. + return 'xf2test.sufficientvelocity.com' + + # @classmethod + # def getAcceptDomains(cls): + # return [cls.getSiteDomain(), + # cls.getSiteDomain().replace('forums.','forum.'), + # cls.getSiteDomain().replace('forums.','')] + + def getSiteURLPattern(self): + ## SV accepts forums.sufficientvelocity.com, forum.sufficientvelocity.com and sufficientvelocity.com + ## all of which redirect to forums. + ## We will use forums. as canonical for all + return super(XF2TestSufficientVelocityComAdapter, self).getSiteURLPattern().replace(re.escape("forums."),r"(forums?\.)?") diff --git a/fanficfare/adapters/base_xenforo2forum_adapter.py b/fanficfare/adapters/base_xenforo2forum_adapter.py new file mode 100644 index 00000000..ee29abec --- /dev/null +++ b/fanficfare/adapters/base_xenforo2forum_adapter.py @@ -0,0 +1,195 @@ +# -*- coding: utf-8 -*- + +# Copyright 2019 FanFicFare team +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from __future__ import absolute_import +import logging +from datetime import datetime +logger = logging.getLogger(__name__) +import re +from xml.dom.minidom import parseString + +from ..htmlcleanup import stripHTML +from .. import exceptions as exceptions + +# py2 vs py3 transition +from ..six import text_type as unicode +from ..six.moves.urllib.error import HTTPError + +from .base_adapter import makeDate +from .base_xenforoforum_adapter import BaseXenForoForumAdapter + +logger = logging.getLogger(__name__) + +class BaseXenForo2ForumAdapter(BaseXenForoForumAdapter): + + def __init__(self, config, url): + logger.info("init url: "+url) + BaseXenForoForumAdapter.__init__(self, config, url) + + @classmethod + def getConfigSections(cls): + "Only needs to be overriden if has additional ini sections." + return ['base_xenforo2forum'] + super(BaseXenForo2ForumAdapter, cls).getConfigSections() + + def performLogin(self): + params = {} + + if self.password: + params['login'] = self.username + params['password'] = self.password + else: + params['login'] = self.getConfig("username") + params['password'] = self.getConfig("password") + + if not params['login']: + raise exceptions.FailedToLogin(self.url,"No username given. Set in personal.ini or enter when prompted.") + + ## need a login token. + data = self._fetchUrl(self.getURLPrefix() + '/login',usecache=False) + # logger.debug(data) + # + find_token='threads|posts)/(?P