mirror of
https://github.com/JimmXinu/FanFicFare.git
synced 2026-04-29 18:35:13 +02:00
Add alternatehistory.com as a base_xenforoforum_adapter. Plus base_xenforoforum_adapter fixes.
This commit is contained in:
parent
3464134aa8
commit
3e897e7758
5 changed files with 70 additions and 5 deletions
|
|
@ -1958,6 +1958,16 @@ extracategories:Star Trek
|
|||
|
||||
website_encodings:Windows-1252,utf8
|
||||
|
||||
[www.alternatehistory.com]
|
||||
## see [base_xenforoforum]
|
||||
|
||||
## Some sites require login (or login for some rated stories) The
|
||||
## program can prompt you, or you can save it in config. In
|
||||
## commandline version, this should go in your personal.ini, not
|
||||
## defaults.ini.
|
||||
#username:YourName
|
||||
#password:yourpassword
|
||||
|
||||
[www.asianfanfics.com]
|
||||
## Some sites require login (or login for some rated stories) The
|
||||
## program can prompt you, or you can save it in config. In
|
||||
|
|
|
|||
|
|
@ -178,6 +178,7 @@ import adapter_gravitytalescom
|
|||
import adapter_lcfanficcom
|
||||
import adapter_noveltrovecom
|
||||
import adapter_inkbunnynet
|
||||
import adapter_alternatehistorycom
|
||||
|
||||
## This bit of complexity allows adapters to be added by just adding
|
||||
## importing. It eliminates the long if/else clauses we used to need
|
||||
|
|
|
|||
40
fanficfare/adapters/adapter_alternatehistorycom.py
Normal file
40
fanficfare/adapters/adapter_alternatehistorycom.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2017 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 base_xenforoforum_adapter import BaseXenForoForumAdapter
|
||||
|
||||
def getClass():
|
||||
return WWWAlternatehistoryComAdapter
|
||||
|
||||
class WWWAlternatehistoryComAdapter(BaseXenForoForumAdapter):
|
||||
|
||||
def __init__(self, config, url):
|
||||
BaseXenForoForumAdapter.__init__(self, config, url)
|
||||
|
||||
# Each adapter needs to have a unique site abbreviation.
|
||||
self.story.setMetadata('siteabbrev','ah')
|
||||
|
||||
@staticmethod # must be @staticmethod, don't remove it.
|
||||
def getSiteDomain():
|
||||
# The site domain. Does have www here, if it uses it.
|
||||
return 'www.alternatehistory.com'
|
||||
|
||||
@classmethod
|
||||
def getURLPrefix(cls):
|
||||
# in case it needs more than just site/
|
||||
return 'https://' + cls.getSiteDomain() + '/forum'
|
||||
|
||||
|
|
@ -79,7 +79,8 @@ class BaseXenForoForumAdapter(BaseSiteAdapter):
|
|||
return cls.getURLPrefix()+"/threads/some-story-name.123456/ "+cls.getURLPrefix()+"/posts/123456/"
|
||||
|
||||
def getSiteURLPattern(self):
|
||||
return r"https?://"+re.escape(self.getSiteDomain())+r"/(?P<tp>threads|posts)/(.+\.)?(?P<id>\d+)/?[^#]*?(#post-(?P<anchorpost>\d+))?$"
|
||||
## need to accept http and https still.
|
||||
return re.escape(self.getURLPrefix()).replace("https","https?")+r"/(?P<tp>threads|posts)/(.+\.)?(?P<id>\d+)/?[^#]*?(#post-(?P<anchorpost>\d+))?$"
|
||||
|
||||
## For adapters, especially base_xenforoforum to override. Make
|
||||
## sure to return unchanged URL if it's NOT a chapter URL. This
|
||||
|
|
@ -104,8 +105,11 @@ class BaseXenForoForumAdapter(BaseSiteAdapter):
|
|||
url.startswith('http://'+self.getSiteDomain()) or
|
||||
url.startswith('https://'+self.getSiteDomain()) ) and \
|
||||
( '/posts/' in url or '/threads/' in url or 'showpost.php' in url or 'goto/post' in url):
|
||||
# brute force way to deal with SB's http->https change when hardcoded http urls.
|
||||
url = url.replace('http://'+self.getSiteDomain(),self.getURLPrefix())
|
||||
## brute force way to deal with SB's http->https change
|
||||
## when hardcoded http urls. Now assumes all
|
||||
## base_xenforoforum sites use https--true as of
|
||||
## 2017-04-28
|
||||
url = url.replace('http://','https://')
|
||||
|
||||
# http://forums.spacebattles.com/showpost.php?p=4755532&postcount=9
|
||||
url = re.sub(r'showpost\.php\?p=([0-9]+)(&postcount=[0-9]+)?',r'/posts/\1/',url)
|
||||
|
|
@ -159,10 +163,10 @@ class BaseXenForoForumAdapter(BaseSiteAdapter):
|
|||
params['register'] = '0'
|
||||
params['cookie_check'] = '1'
|
||||
params['_xfToken'] = ''
|
||||
params['redirect'] = 'https://' + self.getSiteDomain() + '/'
|
||||
params['redirect'] = self.getURLPrefix() + '/'
|
||||
|
||||
## https://forum.questionablequesting.com/login/login
|
||||
loginUrl = 'https://' + self.getSiteDomain() + '/login/login'
|
||||
loginUrl = self.getURLPrefix() + '/login/login'
|
||||
logger.debug("Will now login to URL (%s) as (%s)" % (loginUrl,
|
||||
params['login']))
|
||||
|
||||
|
|
|
|||
|
|
@ -1980,6 +1980,16 @@ extracategories:Star Trek
|
|||
|
||||
website_encodings:Windows-1252,utf8
|
||||
|
||||
[www.alternatehistory.com]
|
||||
## see [base_xenforoforum]
|
||||
|
||||
## Some sites require login (or login for some rated stories) The
|
||||
## program can prompt you, or you can save it in config. In
|
||||
## commandline version, this should go in your personal.ini, not
|
||||
## defaults.ini.
|
||||
#username:YourName
|
||||
#password:yourpassword
|
||||
|
||||
[www.asianfanfics.com]
|
||||
## Some sites require login (or login for some rated stories) The
|
||||
## program can prompt you, or you can save it in config. In
|
||||
|
|
|
|||
Loading…
Reference in a new issue