Don't automatically change the skin, instead throw an error when the required skin isn't set informing the user

This commit is contained in:
cryzed 2014-06-07 03:40:11 +02:00
parent 9bc36c3652
commit c5e5a9bb84

View file

@ -19,7 +19,6 @@ class Voracity2EficComAdapter(BaseSiteAdapter):
BASE_URL = 'http://' + SITE_DOMAIN + '/'
LOGIN_URL = BASE_URL + 'user.php?action=login'
VIEW_STORY_URL_TEMPLATE = BASE_URL + 'viewstory.php?sid=%d'
CHANGE_SKIN_URL_TEMPLATE = BASE_URL + 'user.php?skin=%s'
METADATA_URL_SUFFIX = '&index=1'
AGE_CONSENT_URL_SUFFIX = '&ageconsent=ok&warning=4'
@ -36,7 +35,6 @@ class Voracity2EficComAdapter(BaseSiteAdapter):
self._setURL(self.VIEW_STORY_URL_TEMPLATE % int(story_id))
self.story.setMetadata('siteabbrev', self.SITE_ABBREVIATION)
self.original_skin = None
self.is_logged_in = False
def _login(self):
@ -67,9 +65,6 @@ class Voracity2EficComAdapter(BaseSiteAdapter):
self.is_logged_in = True
def _change_skin(self, name):
self._fetchUrl(self.CHANGE_SKIN_URL_TEMPLATE % name)
def _customized_fetch_url(self, url, exception, parameters=None):
try:
data = self._fetchUrl(url, parameters)
@ -89,14 +84,6 @@ class Voracity2EficComAdapter(BaseSiteAdapter):
def getSiteURLPattern(self):
return re.escape(self.VIEW_STORY_URL_TEMPLATE[:-2]) + r'\d+$'
# Override getStory and append our own functionality. Change the skin back
# to the original one if it was changed during the scraping.
def getStory(self):
story = BaseSiteAdapter.getStory(self)
if self.original_skin:
self._change_skin(self.original_skin)
return story
def extractChapterUrlsAndMetadata(self):
soup = self._customized_fetch_url(self.url + self.METADATA_URL_SUFFIX, urllib2.URLError)
@ -119,14 +106,12 @@ class Voracity2EficComAdapter(BaseSiteAdapter):
url = ''.join([self.url, self.METADATA_URL_SUFFIX, self.AGE_CONSENT_URL_SUFFIX])
soup = self._customized_fetch_url(url, urllib2.URLError)
# If logged in and the skin doesn't match the required skin, change it
# and reload the page
# If logged in and the skin doesn't match the required skin throw an
# error
if self.is_logged_in:
skin = soup.find('select', {'name': 'skin'}).find('option', selected=True)['value']
if skin != self.REQUIRED_SKIN:
self.original_skin = skin
self._change_skin(self.REQUIRED_SKIN)
soup = self._customized_fetch_url(url, urllib2.URLError)
raise exceptions.FailedToDownload('Required skin "%s" must be set in preferences' % self.REQUIRED_SKIN)
pagetitle_div = soup.find('div', id='pagetitle')
self.story.setMetadata('title', pagetitle_div.a.string)