'Generate content/ByDateAdded.html.
Loop through self.books_to_catalog sorted by reverse date, generate HTML.
Input:
books_by_title (list): books, sorted by title
Output:
content/ByDateAdded.html (file)'

def generate_html_by_date_added(self):

    def _add_books_to_html_by_month(this_months_list, dtc):
        if len(this_months_list):
            asl = [i['author_sort'] for i in this_months_list]
            las = max(asl, key=len)
            this_months_list = sorted(this_months_list, key=(lambda x: sort_key(self._kf_books_by_author_sorter_author_sort(x, len(las)))))
            date_string = strftime(u'%B    %Y', current_date.timetuple())
            pIndexTag = Tag(soup, 'p')
            pIndexTag['class'] = 'date_index'
            aTag = Tag(soup, 'a')
            aTag['id'] = ('bda_%s-%s' % (current_date.year, current_date.month))
            pIndexTag.insert(0, aTag)
            pIndexTag.insert(1, NavigableString(date_string))
            divTag.insert(dtc, pIndexTag)
            dtc += 1
            current_author = None
            current_series = None
            for new_entry in this_months_list:
                if (new_entry['author'] != current_author):
                    current_author = new_entry['author']
                    non_series_books = 0
                    current_series = None
                    pAuthorTag = Tag(soup, 'p')
                    pAuthorTag['class'] = 'author_index'
                    aTag = Tag(soup, 'a')
                    if self.opts.generate_authors:
                        aTag['href'] = ('%s.html#%s' % ('ByAlphaAuthor', self.generate_author_anchor(current_author)))
                    aTag.insert(0, NavigableString(current_author))
                    pAuthorTag.insert(0, aTag)
                    divTag.insert(dtc, pAuthorTag)
                    dtc += 1
                if (new_entry['series'] and (new_entry['series'] != current_series)):
                    current_series = new_entry['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(new_entry['series'])))
                        aTag.insert(0, new_entry['series'])
                        pSeriesTag.insert(0, aTag)
                    else:
                        pSeriesTag.insert(0, NavigableString(('%s' % new_entry['series'])))
                    divTag.insert(dtc, pSeriesTag)
                    dtc += 1
                if (current_series and (not new_entry['series'])):
                    current_series = None
                pBookTag = Tag(soup, 'p')
                pBookTag['class'] = 'line_item'
                ptc = 0
                pBookTag.insert(ptc, self.format_prefix(new_entry['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(new_entry['id'])))
                args = self.generate_format_args(new_entry)
                if current_series:
                    formatted_title = self.formatter.safe_format(self.by_month_added_series_title_template, args, (_('error    in') + '    by_month_added_series_title_template:'), self.db.new_api.get_proxy_metadata(book['id']))
                else:
                    formatted_title = self.formatter.safe_format(self.by_month_added_normal_title_template, args, (_('error    in') + '    by_month_added_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(stc, aTag)
                stc += 1
                pBookTag.insert(ptc, spanTag)
                ptc += 1
                divTag.insert(dtc, pBookTag)
                dtc += 1
        return dtc
    def _add_books_to_html_by_date_range(date_range_list, date_range, dtc):
        if len(date_range_list):
            pIndexTag = Tag(soup, 'p')
            pIndexTag['class'] = 'date_index'
            aTag = Tag(soup, 'a')
            aTag['id'] = ('bda_%s' % date_range.replace('    ', ''))
            pIndexTag.insert(0, aTag)
            pIndexTag.insert(1, NavigableString(date_range))
            divTag.insert(dtc, pIndexTag)
            dtc += 1
            for new_entry in date_range_list:
                pBookTag = Tag(soup, 'p')
                pBookTag['class'] = 'line_item'
                ptc = 0
                pBookTag.insert(ptc, self.format_prefix(new_entry['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(new_entry['id'])))
                args = self.generate_format_args(new_entry)
                if new_entry['series']:
                    formatted_title = self.formatter.safe_format(self.by_recently_added_series_title_template, args, (_('error    in') + '    by_recently_added_series_title_template:'), self.db.new_api.get_proxy_metadata(book['id']))
                else:
                    formatted_title = self.formatter.safe_format(self.by_recently_added_normal_title_template, args, (_('error    in') + '    by_recently_added_normal_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
                emTag = Tag(soup, 'em')
                aTag = Tag(soup, 'a')
                if self.opts.generate_authors:
                    aTag['href'] = ('%s.html#%s' % ('ByAlphaAuthor', self.generate_author_anchor(new_entry['author'])))
                aTag.insert(0, NavigableString(new_entry['author']))
                emTag.insert(0, aTag)
                spanTag.insert(stc, emTag)
                stc += 1
                pBookTag.insert(ptc, spanTag)
                ptc += 1
                divTag.insert(dtc, pBookTag)
                dtc += 1
        return dtc
    friendly_name = _('Recently    Added')
    self.update_progress_full_step(('%s    HTML' % friendly_name))
    soup = self.generate_html_empty_header(friendly_name)
    body = soup.find('body')
    btc = 0
    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
    divTag = Tag(soup, 'div')
    dtc = 0
    if self.use_series_prefix_in_titles_section:
        self.books_by_date_range = sorted(self.books_to_catalog, key=(lambda x: (x['timestamp'], x['timestamp'])), reverse=True)
    else:
        nspt = deepcopy(self.books_to_catalog)
        self.books_by_date_range = sorted(nspt, key=(lambda x: (x['timestamp'], x['timestamp'])), reverse=True)
    date_range_list = []
    today_time = nowf().replace(hour=23, minute=59, second=59)
    for (i, date) in enumerate(self.DATE_RANGE):
        date_range_limit = self.DATE_RANGE[i]
        if i:
            date_range = ('%d    to    %d    days    ago' % (self.DATE_RANGE[(i - 1)], self.DATE_RANGE[i]))
        else:
            date_range = ('Last    %d    days' % self.DATE_RANGE[i])
        for book in self.books_by_date_range:
            book_time = book['timestamp']
            delta = (today_time - book_time)
            if (delta.days <= date_range_limit):
                date_range_list.append(book)
            else:
                break
        dtc = _add_books_to_html_by_date_range(date_range_list, date_range, dtc)
        date_range_list = [book]
    self.books_by_month = sorted(self.books_to_catalog, key=(lambda x: (x['timestamp'], x['timestamp'])), reverse=True)
    current_date = datetime.date.fromordinal(1)
    this_months_list = []
    for book in self.books_by_month:
        if ((book['timestamp'].month != current_date.month) or (book['timestamp'].year != current_date.year)):
            dtc = _add_books_to_html_by_month(this_months_list, dtc)
            this_months_list = []
            current_date = book['timestamp'].date()
        this_months_list.append(book)
    _add_books_to_html_by_month(this_months_list, dtc)
    body.insert(btc, divTag)
    outfile_spec = ('%s/ByDateAdded.html' % self.content_dir)
    outfile = open(outfile_spec, 'w')
    outfile.write(soup.prettify())
    outfile.close()
    self.html_filelist_2.append('content/ByDateAdded.html')
