-# Explain what this is.
-intro = """
-Table of Berlin's Corona infection number development by districts, daily
-updated around 9pm.
-
-Abbrevations/explanations:
-CW: Charlottenburg-Wilmersdorf
-FK: Friedrichshain-Kreuzberg
-Li: Lichtenberg
-MH: Marzahn-Hellersdorf
-Mi: Mitte
-Ne: Neukölln
-Pa: Pankow
-Re: Reinickendorf
-Sp: Spandau
-SZ: Steglitz-Zehlendorf
-TS: Tempelhof-Schöneberg
-TK: Treptow-Köpenick
-sum: sum for all the districts
-wsum: sum for last 7 days
-wavg: per-day average of new infections for last 7 days
-winc: incidence (x per 100k inhabitants) of new infections for last 7 days
+# Optimized for web browser viewing.
+import calendar
+if output_type == 'html':
+ print("""<!DOCTYPE html>
+<html>
+<head>
+<style>
+th { text-align: left; vertical-align: bottom; }
+.vertical_header { writing-mode: vertical-rl; transform: rotate(180deg); font-weight: normal; }
+.repeated_head th { padding-top: 0.5em; border-bottom: 1px solid black; }
+.bold { font-weight: bold }
+.date { vertical-align: top; padding-top: 0.5em; }
+</style>
+<title>Berlin's Corona infection numbers, development by districts</title>
+</head>
+<a href="/">home</a> · <a href="/contact.html">contact</a> · <a href="/privacy.html">privacy</a>
+<h1>Berlin's Corona infection numbers, development by districts</h1>
+<p>Updated daily at 9pm based on data from the "Senatsverwaltung für Gesundheit, Pflege und Gleichstellung". <a href="https://plomlompom.com/repos/?p=berlin-corona-table">Source code</a>. <a href="berlin_corona.txt">Plain text view (optimized for terminal curl)</a>.</p>
+<table>
+<tr>
+<th colspan=2></th>""")
+ sorted_dates.reverse()
+ for district in sorted_districts:
+ # Wrap in div because the vertical orientation otherwise fails
+ # in Chromium.
+ print('<th><div class="vertical_header">%s</div></th>' %
+ translate[district])
+ print('</tr>')
+ weekday_count = 0
+ for date in sorted_dates:
+ if weekday_count == 0:
+ print('<tr class="repeated_head">')
+ print('<th>date</th>')
+ print('<th><a href="#symbols">?</a></th>')
+ for district in sorted_districts:
+ print('<th><abbr title="%s">%s</abbr></th>' %
+ (translate[district], district))
+ print('</tr>')
+ print('<tr class="day_row">')
+ weekday = calendar.day_name[datetime.date.fromisoformat(date).weekday()]
+ print('<td class="date">%s<br />%s</td>' % (date, weekday))
+ print('<td><table>')
+ for abbr in ['+', 'Σ', 'Ø', 'i']:
+ print('<tr><th><abbr title="%s">%s</abbr></th></tr>' %
+ (translate[abbr], abbr))
+ print('</table></td>')
+ for district in sorted_districts:
+ district_data = db[district][date]
+ week_sum = week_avg = week_inc = '?'
+ new_infections = district_data['new_infections']
+ if 'week_sum' in district_data:
+ week_sum = '%s' % district_data['week_sum']
+ if 'week_average' in district_data:
+ week_avg = '%.1f' % district_data['week_average']
+ if 'week_incidence' in district_data:
+ week_inc = '%.1f' % district_data['week_incidence']
+ print('<td>')
+ print('<table>')
+ print('<tr><td class="bold">%s</td></tr>' % new_infections)
+ print('<tr><td>%s</td></tr>' % week_sum)
+ print('<tr><td>%s</td></tr>' % week_avg)
+ print('<tr><td>%s</td></tr>' % week_inc)
+ print('</table>')
+ print('</td>')
+ print('</tr>')
+ weekday_count += 1
+ if weekday_count != 7:
+ continue
+ weekday_count = 0
+ print('</table>')
+ print('<h3 id="symbols">Symbols</h3>')
+ print('<dl>')
+ for abbr in ['+', 'Σ', 'Ø', 'i']:
+ print('<dt>%s</dt><dd>%s</dd>' % (abbr, translate[abbr]))
+ print('</dl>')
+ print('</html>')