Add description

This commit is contained in:
nein.wtf 2022-02-17 15:14:22 +01:00
commit 1a71a6296d
2 changed files with 24 additions and 3 deletions

View file

@ -12,8 +12,12 @@ Write([[
body {
padding: 48px;
font-family: sans-serif;
color: #222;
}
span {
span.last-update {
color: #999;
}
span.count {
padding-right: 0.6em;
}
</style>
@ -32,11 +36,28 @@ for v in db:nrows(query) do
rows[#rows + 1] = v
end
Write('<span>')
function format_int(number)
-- taken from https://stackoverflow.com/questions/10989788/format-integer-in-lua#10992898. thanks!
local i, j, minus, int, fraction = tostring(number):find('([-]?)(%d+)([.]?%d*)')
-- reverse the int-string and append a six-per-em to all blocks of 3 digits
thinsp = "&thinsp;"
int = int:reverse():gsub("(%d%d%d)", "%1" .. thinsp:reverse())
-- reverse the int-string back remove an optional six-per-em and put the
-- optional minus and fractional part back
return minus .. int:reverse():gsub("^&thinsp;", "") .. fraction
end
local deaths_yesterday = rows[1]["sum_deaths"] - rows[2]["sum_deaths"]
local description = format_int(rows[1]["sum_deaths"]) .. ' people died from Covid-19. ' .. format_int(deaths_yesterday) .. ' died within the last day.'
Write('<p>' .. description .. ' <span class="last-update">Last update: ' .. rows[1]["last_update"] .. ' UTC</span></p>')
Write('<span class="count">')
for i=1,rows[1]["sum_deaths"] do
Write('🖤')
if i > 0 and i < rows[1]["sum_deaths"] and i % 100 == 0 then
Write('</span><span>')
Write('</span><span class="count">')
end
end
Write('</span>')