'Generate content/ByAlphaAuthor.html.
Loop through self.books_by_author, generate HTML
with anchors for author and index letters.
Input:
books_by_author (list): books, sorted by author
Output:
content/ByAlphaAuthor.html (file)'

def generate_html_by_author(self):

    friendly_name = _('Authors')
    self.update_progress_full_step(('%s    HTML' % friendly_name))
    soup = self.generate_html_empty_header(friendly_name)
    body = soup.find('body')
    btc = 0
    divTag = Tag(soup, 'div')
    dtc = 0
    divOpeningTag = None
    dotc = 0
    divRunningTag = None
    drtc = 0
    book_count = 0
    current_author = ''
    current_letter = ''
    current_series = None
    sort_equivalents = self.establish_equivalencies(self.books_by_author, key='author_sort')
    for (idx, book) in enumerate(self.books_by_author):
        book_count += 1
        if (self.letter_or_symbol(sort_equivalents[idx]) != current_letter):
            if (divOpeningTag is not None):
                divTag.insert(dtc, divOpeningTag)
                dtc += 1
                dotc = 0
            if (divRunningTag is not None):
                divTag.insert(dtc, divRunningTag)
                dtc += 1
                drtc = 0
                divRunningTag = None
            author_count = 0
            divOpeningTag = Tag(soup, 'div')
            if (dtc > 0):
                divOpeningTag['class'] = 'initial_letter'
            dotc = 0
            pIndexTag = Tag(soup, 'p')
            pIndexTag['class'] = 'author_title_letter_index'
            aTag = Tag(soup, 'a')
            current_letter = self.letter_or_symbol(sort_equivalents[idx])
            if (current_letter == self.SYMBOLS):
                aTag['id'] = (self.SYMBOLS + '_authors')
                pIndexTag.insert(0, aTag)
                pIndexTag.insert(1, NavigableString(self.SYMBOLS))
            else:
                aTag['id'] = (self.generate_unicode_name(current_letter) + '_authors')
                pIndexTag.insert(0, aTag)
                pIndexTag.insert(1, NavigableString(sort_equivalents[idx]))
            divOpeningTag.insert(dotc, pIndexTag)
            dotc += 1
        if (book['author'] != current_author):
            current_author = book['author']
            author_count += 1
            if (author_count >= 2):
                if divOpeningTag:
                    divTag.insert(dtc, divOpeningTag)
                    dtc += 1
                    divOpeningTag = None
                    dotc = 0
                if (author_count > 2):
                    divTag.insert(dtc, divRunningTag)
                    dtc += 1
                divRunningTag = Tag(soup, 'div')
                divRunningTag['class'] = 'author_logical_group'
                drtc = 0
            non_series_books = 0
            current_series = None
            pAuthorTag = Tag(soup, 'p')
            pAuthorTag['class'] = 'author_index'
            aTag = Tag(soup, 'a')
            aTag['id'] = ('%s' % self.generate_author_anchor(current_author))
            aTag.insert(0, NavigableString(current_author))
            pAuthorTag.insert(0, aTag)
            if (author_count == 1):
                divOpeningTag.insert(dotc, pAuthorTag)
                dotc += 1
            else:
                divRunningTag.insert(drtc, pAuthorTag)
                drtc += 1
        if (book['series'] and (book['series'] != current_series)):
            current_series = book['series']
            pSeriesTag = Tag(soup, 'p')
            pSeriesTag['class'] = 'series'
            if (self.opts.fmt == 'mobi'):
                pSeriesTag['class'] = 'series_mobi'
            if self.opts.generate_series:
                aTag = Tag(soup, 'a')
                aTag['href'] = ('%s.html#%s' % ('BySeries', self.generate_series_anchor(book['series'])))
                aTag.insert(0, book['series'])
                pSeriesTag.insert(0, aTag)
            else:
                pSeriesTag.insert(0, NavigableString(('%s' % book['series'])))
            if (author_count == 1):
                divOpeningTag.insert(dotc, pSeriesTag)
                dotc += 1
            elif (divRunningTag is not None):
                divRunningTag.insert(drtc, pSeriesTag)
                drtc += 1
        if (current_series and (not book['series'])):
            current_series = None
        pBookTag = Tag(soup, 'p')
        pBookTag['class'] = 'line_item'
        ptc = 0
        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)
        if current_series:
            formatted_title = self.formatter.safe_format(self.by_authors_series_title_template, args, (_('error    in') + '    by_authors_series_title_template:'), self.db.new_api.get_proxy_metadata(book['id']))
        else:
            formatted_title = self.formatter.safe_format(self.by_authors_normal_title_template, args, (_('error    in') + '    by_authors_normal_title_template:'), self.db.new_api.get_proxy_metadata(book['id']))
            non_series_books += 1
        aTag.insert(0, NavigableString(escape(formatted_title)))
        spanTag.insert(ptc, aTag)
        stc += 1
        pBookTag.insert(ptc, spanTag)
        ptc += 1
        if (author_count == 1):
            divOpeningTag.insert(dotc, pBookTag)
            dotc += 1
        elif divRunningTag:
            divRunningTag.insert(drtc, pBookTag)
            drtc += 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(ptc, aTag)
        ptc += 1
        pTag.insert(ptc, NavigableString(('%s' % friendly_name)))
    body.insert(btc, pTag)
    btc += 1
    if (author_count == 1):
        divTag.insert(dtc, divOpeningTag)
        dtc += 1
    elif (divRunningTag is not None):
        divTag.insert(dtc, divRunningTag)
        dtc += 1
    body.insert(btc, divTag)
    outfile_spec = ('%s/ByAlphaAuthor.html' % self.content_dir)
    outfile = open(outfile_spec, 'w')
    outfile.write(soup.prettify())
    outfile.close()
    self.html_filelist_1.append('content/ByAlphaAuthor.html')
