75 lines
1.9 KiB
Lua
75 lines
1.9 KiB
Lua
sqlite3 = require "lsqlite3"
|
|
db = sqlite3.open('covid_deaths.db', sqlite3.OPEN_READONLY)
|
|
|
|
SetStatus(200)
|
|
SetHeader('Content-Type', 'text/html; charset=utf-8')
|
|
Write([[
|
|
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width">
|
|
<title>Dimensions of Covid</title>
|
|
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>⚫</text></svg>">
|
|
<style>
|
|
body {
|
|
padding: 48px;
|
|
font-family: sans-serif;
|
|
color: #444;
|
|
word-break: break-all;
|
|
}
|
|
p {
|
|
word-break: normal;
|
|
}
|
|
span.last-update {
|
|
color: #999;
|
|
}
|
|
span.count {
|
|
padding-right: 0.6em;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
]])
|
|
|
|
local query = [[
|
|
SELECT day, last_update, sum_deaths
|
|
FROM covid_deaths
|
|
ORDER BY day DESC
|
|
LIMIT 2
|
|
]]
|
|
local rows = {}
|
|
for v in db:nrows(query) do
|
|
rows[#rows + 1] = v
|
|
end
|
|
|
|
-- taken from http://lua-users.org/wiki/FormattingNumbers, thanks!
|
|
function format_int(number)
|
|
local formatted = number
|
|
while true do
|
|
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1 %2')
|
|
if (k==0) then
|
|
break
|
|
end
|
|
end
|
|
return formatted
|
|
end
|
|
|
|
local deaths_yesterday = rows[1]["sum_deaths"] - rows[2]["sum_deaths"]
|
|
local description = 'More than ' .. format_int(rows[1]["sum_deaths"]) .. ' people died from Covid-19. ' .. format_int(deaths_yesterday) .. ' deaths have been confirmed within the last day. '
|
|
Write('<p>' .. description .. ' <span class="last-update">Last update: ' .. rows[1]["last_update"] .. ' UTC (<a href="https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data" target="_blank">Source</a>)</span></p>')
|
|
|
|
Write('<span class="count">')
|
|
for i=1,rows[1]["sum_deaths"] do
|
|
Write('•')
|
|
if i < rows[1]["sum_deaths"] and i % 100 == 0 then
|
|
Write('</span><span class="count">')
|
|
end
|
|
end
|
|
Write('</span>')
|
|
|
|
Write([[
|
|
</body>
|
|
</html>
|
|
]])
|