Advertisement
infiniteblock

total

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