Advertisement
infiniteblock

Untitled

Apr 14th, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. -- COVID-19 Tracker for CC
  2. -- Total Cases
  3. -- API: corona.lmao.ninja
  4. -- Program by Lemmmy - GPLv3
  5.  
  6. local util = require("covid19.util")
  7. local gfx = require("covid19.gfx")
  8. local bigfont = require("bigfont")
  9.  
  10. local DATA_URL = "https://corona.lmao.ninja/v2/all"
  11. local CACHE_FILE = ".total-cache.json"
  12.  
  13. local mon, w, h = util.handleMonitorArg(...)
  14.  
  15. local function stat(label, number, colour, y)
  16. local n = util.formatCommas(number)
  17. local colour = gfx.colourToBlit(colour or colours.white)
  18. bigfont.blitOn(mon, 1, string.format("%s: %s", label, n), ("0"):rep(#label + 2) .. colour:rep(#n), ("f"):rep(#label + 2 + #n), nil, y)
  19. end
  20.  
  21. local function main()
  22. mon.clear()
  23.  
  24. local centerY = gfx.drawLoading(mon)
  25. local data = util.cachedJSONRequest(DATA_URL, CACHE_FILE)
  26. gfx.clearLoading(mon, centerY)
  27.  
  28. mon.setTextColour(colours.white)
  29. bigfont.writeOn(mon, 2, "COVID-19", nil, 2)
  30.  
  31. stat("Confirmed cases", data.cases, colours.orange, 11)
  32. stat("Deaths", data.deaths, colours.red, 15)
  33. stat("Recoveries", data.recovered, colours.green, 19)
  34.  
  35. mon.setTextColour(colours.lightGrey)
  36. local updated = "Last updated: " .. os.date("%Y/%m/%d %H:%M:%S", math.ceil(data.updated / 1000)) .. " UTC"
  37. gfx.writeCentred(mon, w, updated, h - 1)
  38. end
  39.  
  40. util.mainLoop(main)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement