How to use the fanficfare.htmlcleanup.stripHTML function in FanFicFare

To help you get started, we’ve selected a few FanFicFare examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JimmXinu / FanFicFare / fanficfare / adapters / adapter_scarheadnet.py View on Github external
raise exceptions.AdultCheckRequired(self.url)

        if "Access denied. This story has not been validated by the adminstrators of this site." in data:
            raise exceptions.AccessDenied(self.getSiteDomain() +" says: Access denied. This story has not been validated by the adminstrators of this site.")

        # use BeautifulSoup HTML parser to make everything easier to find.
        soup = self.make_soup(data)
        # print data

        # Now go hunting for all the meta data and the chapter list.

        pagetitle = soup.find('tr',{'valign':'top'})

        ## Title
        a = pagetitle.find('a', href=re.compile(r'viewstory.php\?sid='+self.story.getMetadata('storyId')+"$"))
        self.story.setMetadata('title',stripHTML(a))

        # Find authorid and URL from... author url.
        a = pagetitle.find('a', href=re.compile(r"viewuser.php\?uid=\d+"))
        self.story.setMetadata('authorId',a['href'].split('=')[1])
        self.story.setMetadata('authorUrl','http://'+self.host+'/'+a['href'])
        self.story.setMetadata('author',a.string)

        # Find the chapters:
        for chapter in soup.findAll('a', href=re.compile(r'viewstory.php\?sid='+self.story.getMetadata('storyId')+"&chapter=\d+$")):
            # just in case there's tags, like <i> in chapter titles.
            self.chapterUrls.append((stripHTML(chapter),'http://'+self.host+'/'+chapter['href']+addurl))

        self.story.setMetadata('numChapters',len(self.chapterUrls))

        # eFiction sites don't help us out a lot with their meta data
        # formating, so it's a little ugly.</i>
github JimmXinu / FanFicFare / fanficfare / adapters / adapter_bloodshedversecom.py View on Github external
soup = self._customized_fetch_url(author_url)

        # Ignore first list_box div, it only contains the author information
        for list_box in soup('div', {'class': 'list_box'})[1:]:
            url = list_box.find('a', {'class': 'fictitle'})['href']
            query_data = _get_query_data(url)

            # Found the div containing the story's metadata; break the loop and
            # parse the element
            if query_data['no'] == story_no:
                break
        else:
            raise exceptions.FailedToDownload(self.url)

        title_anchor = list_box.find('a', {'class': 'fictitle'})
        self.story.setMetadata('title', stripHTML(title_anchor))

        author_anchor = title_anchor.findNextSibling('a')
        self.story.setMetadata('author', stripHTML(author_anchor))
        self.story.setMetadata('authorId', _get_query_data(author_anchor['href'])['who'])
        self.story.setMetadata('authorUrl', urlparse.urljoin(self.url, author_anchor['href']))

        list_review = list_box.find('div', {'class': 'list_review'})
        reviews = stripHTML(list_review.a).split(' ', 1)[0]
        self.story.setMetadata('reviews', reviews)

        summary_div = list_box.find('div', {'class': 'list_summary'})
        if not self.getConfig('keep_summary_html'):
            summary = ''.join(summary_div(text=True))
        else:
            summary = self.utf8FromSoup(author_url, summary_div)
github JimmXinu / FanFicFare / fanficfare / adapters / adapter_ashwindersycophanthexcom.py View on Github external
self.story.setMetadata('author',a.string)
        asoup = self.make_soup(self._fetchUrl(self.story.getMetadata('authorUrl')))
		
        try:
            # in case link points somewhere other than the first chapter
            a = soup.findAll('option')[1]['value']
            self.story.setMetadata('storyId',a.split('=',)[1])
            url = 'http://'+self.host+'/'+a
            soup = self.make_soup(self._fetchUrl(url))
        except:
            pass
		
        for info in asoup.findAll('table', {'width' : '100%', 'bordercolor' : re.compile(r'#')}):
            a = info.find('a', href=re.compile(r'viewstory.php\?sid='+self.story.getMetadata('storyId')+"$"))
            if a != None:
                self.story.setMetadata('title',stripHTML(a))
                break
		

        # Find the chapters:
        chapters=soup.findAll('a', href=re.compile(r'viewstory.php\?sid=\d+&amp;i=1$'))
        if len(chapters) == 0:
            self.chapterUrls.append((self.story.getMetadata('title'),url))
        else:
            for chapter in chapters:
                # just in case there's tags, like <i> in chapter titles.
                self.chapterUrls.append((stripHTML(chapter),'http://'+self.host+'/'+chapter['href']))

        self.story.setMetadata('numChapters',len(self.chapterUrls))

        # eFiction sites don't help us out a lot with their meta data
        # formating, so it's a little ugly.</i>
github JimmXinu / FanFicFare / fanficfare / adapters / adapter_whoficcom.py View on Github external
# - get chapter list, if not one-shot.

        url = self.url+'&chapter=1'
        logger.debug("URL: "+url)

        # use BeautifulSoup HTML parser to make everything easier to find.
        try:
            soup = self.make_soup(self._fetchUrl(url))
        except HTTPError as e:
            if e.code == 404:
                raise exceptions.StoryDoesNotExist(self.url)
            else:
                raise e

        # pull title(title) and author from the HTML title.
        title = stripHTML(soup.find('title'))
        logger.debug('Title: %s' % title)
        title = title.split('::')[1].strip()
        self.story.setMetadata('title',title.split(' by ')[0].strip())
        self.story.setMetadata('author',title.split(' by ')[1].strip())

        # Find authorid and URL from... author url.
        a = soup.find('a', href=re.compile(r"viewuser.php"))
        self.story.setMetadata('authorId',a['href'].split('=')[1])
        self.story.setMetadata('authorUrl','https://'+self.host+'/'+a['href'])

        # Find the chapter selector
        select = soup.find('select', { 'name' : 'chapter' } )

        if select is None:
            # no selector found, so it's a one-chapter story.
            self.add_chapter(self.story.getMetadata('title'),url)
github JimmXinu / FanFicFare / fanficfare / adapters / adapter_portkeyorg.py View on Github external
## Title
        titlea = authsoup.find('a', href=re.compile(r'/story/'+self.story.getMetadata('storyId')+"$"))
        self.story.setMetadata('title',stripHTML(titlea))
        metablock = titlea.parent

        # Find the chapters:
        for chapter in soup.find('select',{'name':'select5'}).findAll('option', {'value':re.compile(r'/story/'+self.story.getMetadata('storyId')+"/\d+$")}):
            # just in case there's tags, like <i> in chapter titles.
            chtitle = stripHTML(chapter)
            if not chtitle:
                chtitle = "(Untitled Chapter)"
            self.chapterUrls.append((chtitle,'http://'+self.host+chapter['value']))

        if len(self.chapterUrls) == 0:
            self.chapterUrls.append((stripHTML(self.story.getMetadata('title')),url))

        self.story.setMetadata('numChapters',len(self.chapterUrls))

        # eFiction sites don't help us out a lot with their meta data
        # formating, so it's a little ugly.

        # utility method
        def defaultGetattr(d,k):
            try:
                return d[k]
            except:
                return ""
        # <span class="dark-small-bold">Contents:</span> <span class="small-grey">NC17 </span>
        # <span class="dark-small-bold">Published: </span><span class="small-grey">12/11/07</span>
        # <span class="dark-small-bold"><br>
        # Description:</span> <span class="small-black">A special book helps Harry tap into the power the Dark Lord knows not.  Of course it’s a book on sex magic and rituals… but Harry’s not complaining.  Spurned on by the ghost of a pervert founder, Harry leads his friends in the hunt for Voldemort’s Horcruxes.</span></i>
github JimmXinu / FanFicFare / fanficfare / adapters / adapter_thequidditchpitchorg.py View on Github external
for warning in warningstext:
                    self.story.addToList('warnings',warning.string)

            if 'Completed' in label:
                if 'Yes' in value:
                    self.story.setMetadata('status', 'Completed')
                else:
                    self.story.setMetadata('status', 'In-Progress')

            if 'Published' in label:
                self.story.setMetadata('datePublished', makeDate(stripHTML(value), self.dateformat))
            
            if 'Updated' in label:
                # there's a stray [ at the end.
                #value = value[0:-1]
                self.story.setMetadata('dateUpdated', makeDate(stripHTML(value), self.dateformat))

        try:
            # Find Series name from series URL.
            a = soup.find('a', href=re.compile(r"viewseries.php\?seriesid=\d+"))
            series_name = a.string
            series_url = 'http://'+self.host+'/'+a['href']

            # use BeautifulSoup HTML parser to make everything easier to find.
            seriessoup = bs.BeautifulSoup(self._fetchUrl(series_url))
            storyas = seriessoup.findAll('a', href=re.compile(r'^viewstory.php\?sid=\d+$'))
            i=1
            for a in storyas:
                if a['href'] == ('viewstory.php?sid='+self.story.getMetadata('storyId')):
                    self.setSeries(series_name, i)
                    self.story.setMetadata('seriesUrl',series_url)
                    break
github JimmXinu / FanFicFare / fanficfare / adapters / adapter_wuxiaworldco.py View on Github external
logger.debug('URL: %s', self.url)
        try:
            data = self._fetchUrl(self.url)
        except HTTPError as exception:
            if exception.code == 404:
                raise exceptions.StoryDoesNotExist('404 error: {}'.format(self.url))
            raise exception

        soup = self.make_soup(data)
        info = soup.select_one('#info')
        self.story.setMetadata('title', stripHTML(info.h1))
        self.setCoverImage(self.url, soup.select_one('#fmimg &gt; img')['src'])

        info_paragraphs = info('p')
        # Unicode strings because ':' isn't ':', but \xef\xbc\x9a
        author = stripHTML(info_paragraphs[0]).replace(u'Author:', '', 1)
        self.story.setMetadata('author', author)
        self.story.setMetadata('authorId', author)
        datestr = stripHTML(info_paragraphs[2]).replace(u'UpdateTime:', '', 1)
        date = None
        try:
            ## Some older stories use a different date format.
            date = makeDate(datestr, self.NEW_DATE_FORMAT)
        except ValueError:
            date = makeDate(datestr, self.OLD_DATE_FORMAT)
        if date:
            self.story.setMetadata('dateUpdated', date)

        intro = soup.select_one('#intro')
        # Strip <strong>Description</strong>
        if intro.strong:
            intro.strong.decompose()
github JimmXinu / FanFicFare / fanficfare / adapters / adapter_ashwindersycophanthexcom.py View on Github external
if warning != ' none':
                        self.story.addToList('warnings',warning)

            if 'Completed' in label:
                if 'Yes' in value:
                    self.story.setMetadata('status', 'Completed')
                else:
                    self.story.setMetadata('status', 'In-Progress')

            if 'Published' in label:
                self.story.setMetadata('datePublished', makeDate(stripHTML(value), self.dateformat))

            if 'Updated' in label:
                # there's a stray [ at the end.
                #value = value[0:-1]
                self.story.setMetadata('dateUpdated', makeDate(stripHTML(value), self.dateformat))
github JimmXinu / FanFicFare / fanficfare / adapters / adapter_potionsandsnitches.py View on Github external
self.story.addToList('warnings',stripHTML(warning))

            if 'Genre' in label:
                genres = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=class'))
                for genre in genres:
                    self.story.addToList('genre',stripHTML(genre))

            if 'Takes Place' in label:
                takesplaces = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=class'))
                for takesplace in takesplaces:
                    self.story.addToList('takesplaces',stripHTML(takesplace))

            if 'Snape flavour' in label:
                snapeflavours = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=class'))
                for snapeflavour in snapeflavours:
                    self.story.addToList('snapeflavours',stripHTML(snapeflavour))

            if 'Tags' in label:
                sitetags = labelspan.parent.findAll('a',href=re.compile(r'browse.php\?type=class'))
                for sitetag in sitetags:
                    self.story.addToList('sitetags',stripHTML(sitetag))

            if 'Completed' in label:
                if 'Yes' in value:
                    self.story.setMetadata('status', 'Completed')
                else:
                    self.story.setMetadata('status', 'In-Progress')

            if 'Published' in label:
                # limit date values, there's some extra chars.
                self.story.setMetadata('datePublished', makeDate(stripHTML(value[:12]), "%d %b %Y"))
github JimmXinu / FanFicFare / fanficfare / adapters / adapter_fimfictionnet.py View on Github external
# link, so just reuse the URL. Makes it clear it's
                    # an external link leading outside of the fanfic
                    # site, at least.
                    self.story.setMetadata('coverSource', coverSource['href'])

        # fimf has started including extra stuff inside the description div.
        # specifically, the prequel link
        description = storyContentBox.find("span", {"class":"description-text"})
        description.name='div' # change to div, technically, spans
                               # aren't supposed to contain <p>'s.
        descdivstr = u"%s"%description # string, but not stripHTML'ed
        #The link to the prequel is embedded in the description text, so erring
        #on the side of caution and wrapping this whole thing in a try block.
        #If anything goes wrong this probably wasn't a valid prequel link.
        try:
            if "This story is a sequel to" in stripHTML(description):
                link = description.find('a') # assume first link.
                self.story.setMetadata("prequelUrl", 'https://'+self.host+link["href"])
                self.story.setMetadata("prequel", stripHTML(link))
                if not self.getConfig('keep_prequel_in_description',False):
                    hrstr=u"</p><hr>"
                    descdivstr = u'<div class="description">'+descdivstr[descdivstr.index(hrstr)+len(hrstr):]
        except:
            logger.info("Prequel parsing failed...")
        self.setDescription(self.url,descdivstr)

        # Find the newest and oldest chapter dates
        storyData = storyContentBox.find('ul', {'class':'chapters'})
        oldestChapter = None
        newestChapter = None
        self.newestChapterNum = None # save for comparing during update.
        # Scan all chapters to find the oldest and newest, on</div>