mirror of
https://github.com/JimmXinu/FanFicFare.git
synced 2025-12-28 03:36:06 +01:00
Add forums.sufficientvelocity.com as a child of SB adapter.
This commit is contained in:
parent
fcc5c1424d
commit
a9aa7ba505
3 changed files with 54 additions and 9 deletions
|
|
@ -136,6 +136,7 @@ import adapter_devianthearts
|
|||
import adapter_tgstorytimecom
|
||||
import adapter_itcouldhappennet
|
||||
import adapter_forumsspacebattlescom
|
||||
import adapter_forumssufficientvelocitycom
|
||||
|
||||
## This bit of complexity allows adapters to be added by just adding
|
||||
## importing. It eliminates the long if/else clauses we used to need
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class ForumsSpacebattlesComAdapter(BaseSiteAdapter):
|
|||
self.story.setMetadata('storyId',m.group('id'))
|
||||
|
||||
# normalized story URL.
|
||||
self._setURL('https://' + self.getSiteDomain() + '/threads/'+self.story.getMetadata('storyId')+'/')
|
||||
self._setURL(self.getURLPrefix() + '/threads/'+self.story.getMetadata('storyId')+'/')
|
||||
else:
|
||||
raise exceptions.InvalidStoryURL(url,
|
||||
self.getSiteDomain(),
|
||||
|
|
@ -71,13 +71,16 @@ class ForumsSpacebattlesComAdapter(BaseSiteAdapter):
|
|||
# The site domain. Does have www here, if it uses it.
|
||||
return 'forums.spacebattles.com'
|
||||
|
||||
@classmethod
|
||||
def getURLPrefix(cls):
|
||||
# The site domain. Does have www here, if it uses it.
|
||||
return 'https://' + cls.getSiteDomain()
|
||||
|
||||
@classmethod
|
||||
def getSiteExampleURLs(cls):
|
||||
return "https://"+cls.getSiteDomain()+"/threads/some-story-name.123456/"
|
||||
return cls.getURLPrefix()+"/threads/some-story-name.123456/"
|
||||
|
||||
def getSiteURLPattern(self):
|
||||
# http://archiveofourown.org/collections/Smallville_Slash_Archive/works/159770
|
||||
# Discard leading zeros from story ID numbers--AO3 doesn't use them in it's own chapter URLs.
|
||||
return r"https?://"+re.escape(self.getSiteDomain())+r"/threads/(.+\.)?(?P<id>\d+)/"
|
||||
|
||||
def use_pagecache(self):
|
||||
|
|
@ -106,7 +109,7 @@ class ForumsSpacebattlesComAdapter(BaseSiteAdapter):
|
|||
|
||||
a = soup.find('h3',{'class':'userText'}).find('a')
|
||||
self.story.addToList('authorId',a['href'].split('/')[1])
|
||||
self.story.addToList('authorUrl','https://'+self.getSiteDomain()+'/'+a['href'])
|
||||
self.story.addToList('authorUrl',self.getURLPrefix()+'/'+a['href'])
|
||||
self.story.addToList('author',a.text)
|
||||
|
||||
self.story.addToList('genre','ForumFic')
|
||||
|
|
@ -120,11 +123,11 @@ class ForumsSpacebattlesComAdapter(BaseSiteAdapter):
|
|||
# try threadmarks first, require at least 2.
|
||||
threadmarksa = soup.find('a',{'class':'threadmarksTrigger'})
|
||||
if threadmarksa:
|
||||
soupmarks = self.make_soup(self._fetchUrl('https://'+self.getSiteDomain()+'/'+threadmarksa['href']))
|
||||
soupmarks = self.make_soup(self._fetchUrl(self.getURLPrefix()+'/'+threadmarksa['href']))
|
||||
markas = soupmarks.find('ol',{'class':'overlayScroll'}).find_all('a')
|
||||
if len(markas) > 1:
|
||||
for (url,name) in [ (x['href'],stripHTML(x)) for x in markas ]:
|
||||
self.chapterUrls.append((name,'https://'+self.getSiteDomain()+'/'+url))
|
||||
self.chapterUrls.append((name,self.getURLPrefix()+'/'+url))
|
||||
|
||||
# otherwise, use first post links--include first post since that's
|
||||
if not self.chapterUrls:
|
||||
|
|
@ -132,9 +135,11 @@ class ForumsSpacebattlesComAdapter(BaseSiteAdapter):
|
|||
self.chapterUrls.append(("First Post",self.url))
|
||||
for (url,name) in [ (x['href'],stripHTML(x)) for x in firstpost.find_all('a') ]:
|
||||
if not url.startswith('http'):
|
||||
url = 'https://'+self.getSiteDomain()+'/'+url
|
||||
url = self.getURLPrefix()+'/'+url
|
||||
|
||||
if (url.startswith('https://'+self.getSiteDomain()) or url.startswith('http://'+self.getSiteDomain())) and ('/posts/' in url or '/threads/' in url):
|
||||
if (url.startswith(self.getURLPrefix()) or url.startswith('http://'+self.getSiteDomain())) and ('/posts/' in url or '/threads/' in url):
|
||||
# brute force way to deal with SB's http->https change when hardcoded http urls.
|
||||
url.replace('http://'+self.getSiteDomain(),self.getURLPrefix())
|
||||
self.chapterUrls.append((name,url))
|
||||
|
||||
self.story.setMetadata('numChapters',len(self.chapterUrls))
|
||||
|
|
|
|||
39
fanficfare/adapters/adapter_forumssufficientvelocitycom.py
Normal file
39
fanficfare/adapters/adapter_forumssufficientvelocitycom.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2015 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 adapter_forumsspacebattlescom import ForumsSpacebattlesComAdapter
|
||||
|
||||
def getClass():
|
||||
return ForumsSufficientVelocityComAdapter
|
||||
|
||||
class ForumsSufficientVelocityComAdapter(ForumsSpacebattlesComAdapter):
|
||||
|
||||
def __init__(self, config, url):
|
||||
ForumsSpacebattlesComAdapter.__init__(self, config, url)
|
||||
|
||||
# Each adapter needs to have a unique site abbreviation.
|
||||
self.story.setMetadata('siteabbrev','fsv')
|
||||
|
||||
@staticmethod # must be @staticmethod, don't remove it.
|
||||
def getSiteDomain():
|
||||
# The site domain. Does have www here, if it uses it.
|
||||
return 'forums.sufficientvelocity.com'
|
||||
|
||||
@classmethod
|
||||
def getURLPrefix(cls):
|
||||
# The site domain. Does have www here, if it uses it.
|
||||
return 'http://' + cls.getSiteDomain()
|
||||
Loading…
Reference in a new issue