def mkwww_wordpage(answer): uses = all_uses[answer] h = '' # h += pubyear.pubyear_html([ (ca.pubyear()[0], ca.pubyear()[1], 1) for ca in uses ]) h += '<hr/>' h += '<div>Clued as: ' + html_select_options([ ca.clue for ca in uses ]) + '</div>' h += '<h2>%d uses</h2>' % len(uses) h += '<table>' for ca in sorted(uses, reverse=True, key=lambda ca: ca.date): try: md = metadb.xd_puzzle(ca.xdid()) h += td(md.xdid, ca.clue, md.Author, md.Copyright) except Exception as e: h += td(ca.xdid, ca.clue, str(e)) if utils.get_args().debug: raise h += '</table>' # h += '<hr/>' # h += '<div>Mutations: ' # h +='</div>' return h
def pubyear_html(pub, year): calendars_html = '<table class="puzzles">' colnames = [year] + pubyear_header calendars_html += html.table_row(colnames, colnames, tag='th') # write out /pub/nyt199x c_grids = {} # utils.info('Generating meta for {pub}{year}'.format(**locals())) for row in sorted(metadb.xd_similar(pub + year)): dt = utils.parse_iso8601(row.xdid) dt2 = utils.parse_iso8601(row.match_xdid) if not dt or not dt2: continue if dt < dt2: continue # dt = row["date"] # without - as GridCalendar needs; or fix GC if dt not in c_grids: c_grids[dt] = {'title': '', 'class': ''} if row.match_pct == 0: continue c_grids[dt]['link'] = '/pub/' + row.xdid matchxdid = row.match_xdid aut1 = metadb.get_author(row.xdid) or '' aut2 = metadb.get_author(matchxdid) or '' # if aut1 is None or aut2 is None: # continue pct = row.match_pct similargrids = '(%s%%) %s [%s]\n' % (pct, aut2, matchxdid) c_grids[dt]["title"] += similargrids ##deduce_similarity_type c_grids[dt]["class"] += ret_classes(aut1, aut2, pct) c_grids_b = {} # For those are not in c_grids # Generate grids for available puzzles for row in metadb.xd_puzzles(pub + year): if row.Date and row.Date not in c_grids_b and row.Date not in c_grids: # add styles only for those are not similar etc. c_grids_b[row.Date] = { 'title': '', 'class': 'privxd' if int(row.Date[:4]) > 1965 else 'pubxd', } # Generate calendars z = c_grids.copy() z.update(c_grids_b) if year[-1] == 's': # decade from_year = int(year[:4]) to_year = int(year[:4]) + 10 else: from_year = int(year) to_year = int(year) + 1 for year in range(from_year, to_year): for month in range(1, 13): dups_table = [] for dt, d in c_grids.items(): if not dt.startswith("%s-%02d" % (year, month)): continue row_dict = {} # Map row and style xdid = pub + dt puzmd = metadb.xd_puzzle(xdid) if not puzmd: continue row_dict['class'] = d['class'] row_dict['tag_params'] = { 'onclick': 'location.href=\'/pub/%s\'' % xdid, 'class': d['class'] + ' hrefrow puzrow', } row_dict['row'] = [ xdid, puzmd.Date, puzmd.Size, puzmd.Title, puzmd.Author, puzmd.Editor, puzmd.Copyright, puzmd.A1_D1, d["title"].replace("\n", "<br/>") ] dups_table.append(row_dict) calendars_html += '<tr class="calendar"><td class="calendar" rowspan="%s">' % ( len(dups_table) + 1) calendars_html += html.GridCalendar(z).formatmonth( int(year), month) + '</td></tr>' for r in sorted(dups_table, key=lambda x: x['row'][1]): calendars_html += html.table_row(r["row"], pubyear_header, tag_params=r['tag_params']) calendars_html += '</table>' ret = '''%s <div class="calendars">%s</div> <hr/>''' % (legend, calendars_html) return ret
def pubyear_html(pub, year): calendars_html = '<table class="puzzles">' colnames = [ year ] + pubyear_header calendars_html += html.table_row(colnames, colnames, tag='th') # write out /pub/nyt199x c_grids = {} # utils.info('Generating meta for {pub}{year}'.format(**locals())) for row in sorted(metadb.xd_similar(pub+year)): dt = utils.parse_iso8601(row.xdid) dt2 = utils.parse_iso8601(row.match_xdid) if not dt or not dt2: continue if dt < dt2: continue # dt = row["date"] # without - as GridCalendar needs; or fix GC if dt not in c_grids: c_grids[dt] = { 'title': '', 'class': '' } if row.match_pct == 0: continue c_grids[dt]['link'] = '/pub/' + row.xdid matchxdid = row.match_xdid aut1 = metadb.get_author(row.xdid) or '' aut2 = metadb.get_author(matchxdid) or '' # if aut1 is None or aut2 is None: # continue pct = row.match_pct similargrids = '(%s%%) %s [%s]\n' % (pct, aut2, matchxdid) c_grids[dt]["title"] += similargrids ##deduce_similarity_type c_grids[dt]["class"] += ret_classes(aut1, aut2, pct) c_grids_b = {} # For those are not in c_grids # Generate grids for available puzzles for row in metadb.xd_puzzles(pub+year): if row.Date and row.Date not in c_grids_b and row.Date not in c_grids: # add styles only for those are not similar etc. c_grids_b[row.Date] = { 'title': '', 'class': 'privxd' if int(row.Date[:4]) > 1965 else 'pubxd', } # Generate calendars z = c_grids.copy() z.update(c_grids_b) if year[-1] == 's': # decade from_year = int(year[:4]) to_year = int(year[:4]) + 10 else: from_year = int(year) to_year = int(year) + 1 for year in range(from_year, to_year): for month in range(1, 13): dups_table = [] for dt, d in c_grids.items(): if not dt.startswith("%s-%02d" % (year, month)): continue row_dict = {} # Map row and style xdid = pub + dt puzmd = metadb.xd_puzzle(xdid) if not puzmd: continue row_dict['class'] = d['class'] row_dict['tag_params'] = { 'onclick': 'location.href=\'/pub/%s\'' % xdid, 'class': d['class'] + ' hrefrow puzrow', } row_dict['row'] = [ xdid, puzmd.Date, puzmd.Size, puzmd.Title, puzmd.Author, puzmd.Editor, puzmd.Copyright, puzmd.A1_D1, d["title"].replace("\n", "<br/>") ] dups_table.append(row_dict) calendars_html += '<tr class="calendar"><td class="calendar" rowspan="%s">' % (len(dups_table) + 1) calendars_html += html.GridCalendar(z).formatmonth(int(year), month) + '</td></tr>' for r in sorted(dups_table, key=lambda x: x['row'][1]): calendars_html += html.table_row(r["row"], pubyear_header, tag_params=r['tag_params']) calendars_html += '</table>' ret = '''%s <div class="calendars">%s</div> <hr/>''' % (legend, calendars_html) return ret