'Generate content/BySeries.html.
Search database for books in series.
Input:
database
Output:
content/BySeries.html (file)'

def generate_html_by_series(self):

    friendly_name = _('Series')
    self.update_progress_full_step(('%s    HTML' % friendly_name))
    self.opts.sort_by = 'series'
    self.books_by_series = [i for i in self.books_to_catalog if i['series']]
    self.books_by_series = sorted(self.books_by_series, key=(lambda x: sort_key(self._kf_books_by_series_sorter(x))))
    if (not self.books_by_series):
        self.opts.generate_series = False
        self.opts.log('        no    series    found    in    selected    books,    skipping    Series    section')
        return
    for book in self.books_by_series:
        book['series_sort'] = self.generate_sort_title(book['series'])
    sort_equivalents = self.establish_equivalencies(self.books_by_series, key='series_sort')
    soup = self.generate_html_empty_header(friendly_name)
    body = soup.find('body')
    btc = 0
    divTag = Tag(soup, 'div')
    dtc = 0
    current_letter = ''
    current_series = None
    series_count = 0
    for (idx, book) in enumerate(self.books_by_series):
        if (self.letter_or_symbol(sort_equivalents[idx]) != current_letter):
            current_letter = self.letter_or_symbol(sort_equivalents[idx])
            pIndexTag = Tag(soup, 'p')
            pIndexTag['class'] = 'series_letter_index'
            aTag = Tag(soup, 'a')
            if (current_letter == self.SYMBOLS):
                aTag['id'] = (self.SYMBOLS + '_series')
                pIndexTag.insert(0, aTag)
                pIndexTag.insert(1, NavigableString(self.SYMBOLS))
            else:
                aTag['id'] = (self.generate_unicode_name(current_letter) + '_series')
                pIndexTag.insert(0, aTag)
                pIndexTag.insert(1, NavigableString(sort_equivalents[idx]))
            divTag.insert(dtc, pIndexTag)
            dtc += 1
        if (book['series'] != current_series):
            series_count += 1
            current_series = book['series']
            pSeriesTag = Tag(soup, 'p')
            pSeriesTag['class'] = 'series'
            if (self.opts.fmt == 'mobi'):
                pSeriesTag['class'] = 'series_mobi'
            aTag = Tag(soup, 'a')
            aTag['id'] = self.generate_series_anchor(book['series'])
            pSeriesTag.insert(0, aTag)
            pSeriesTag.insert(1, NavigableString(('%s' % book['series'])))
            divTag.insert(dtc, pSeriesTag)
            dtc += 1
        pBookTag = Tag(soup, 'p')
        pBookTag['class'] = 'line_item'
        ptc = 0
        book['prefix'] = self.discover_prefix(book)
        pBookTag.insert(ptc, self.format_prefix(book['prefix']))
        ptc += 1
        spanTag = Tag(soup, 'span')
        spanTag['class'] = 'entry'
        stc = 0
        aTag = Tag(soup, 'a')
        if self.opts.generate_descriptions:
            aTag['href'] = ('book_%d.html' % int(float(book['id'])))
        args = self.generate_format_args(book)
        formatted_title = self.formatter.safe_format(self.by_series_title_template, args, (_('error    in') + '    by_series_title_template:'), self.db.new_api.get_proxy_metadata(book['id']))
        aTag.insert(0, NavigableString(escape(formatted_title)))
        spanTag.insert(stc, aTag)
        stc += 1
        spanTag.insert(stc, NavigableString('    &middot;    '))
        stc += 1
        aTag = Tag(soup, 'a')
        if self.opts.generate_authors:
            aTag['href'] = ('%s.html#%s' % ('ByAlphaAuthor', self.generate_author_anchor(escape('    &    '.join(book['authors'])))))
        aTag.insert(0, NavigableString('    &amp;    '.join(book['authors'])))
        spanTag.insert(stc, aTag)
        stc += 1
        pBookTag.insert(ptc, spanTag)
        ptc += 1
        divTag.insert(dtc, pBookTag)
        dtc += 1
    pTag = Tag(soup, 'p')
    pTag['class'] = 'title'
    ptc = 0
    aTag = Tag(soup, 'a')
    aTag['id'] = 'section_start'
    pTag.insert(ptc, aTag)
    ptc += 1
    if (not self.generate_for_kindle_mobi):
        aTag = Tag(soup, 'a')
        anchor_name = friendly_name.lower()
        aTag['id'] = anchor_name.replace('    ', '')
        pTag.insert(0, aTag)
        pTag.insert(1, NavigableString(('%s' % friendly_name)))
    body.insert(btc, pTag)
    btc += 1
    body.insert(btc, divTag)
    outfile_spec = ('%s/BySeries.html' % self.content_dir)
    outfile = open(outfile_spec, 'w')
    outfile.write(soup.prettify())
    outfile.close()
    self.html_filelist_1.append('content/BySeries.html')
