Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local net = require("internet")
- local term = require("term")
- local os = require("os")
- local io = require("io")
- local gpu = component.gpu
- JSON_LIB = "https://raw.githubusercontent.com/sziberov/OpenComputers/master/lib/json.lua"
- BIGFONT_LIB = "https://raw.githubusercontent.com/iesika/iesika-OCPrograms/master/OC-bigfont/lib/bigfont.lua"
- function getFontURL(size)
- return "https://raw.githubusercontent.com/iesika/iesika-OCPrograms/master/OC-bigfont/lib/bigfont-size" .. tostring(size) .. ".hex"
- end
- function download(url, path)
- local r = net.request(url)
- local f = io.open(path, "w")
- local chunk = r()
- while not (chunk == nil) do
- f:write(chunk)
- chunk = r()
- end
- f:close()
- end
- if not component.isAvailable("internet") then
- io.stderr:write("This program requires an internet card to run.")
- return
- end
- local status, json = pcall(require, "json")
- if (not status) or json == nil then
- print("Json parser not found, downloading")
- download(JSON_LIB, "/lib/json.lua")
- status, json = pcall(require, "json")
- if (not status) or json == nil then
- print("Couldn't install json parser, aborting.")
- os.exit()
- end
- print("Json parser installed")
- end
- local status, bigfont = pcall(require, "bigfont")
- if (not status) or bigfont == nil then
- print("BigFont library not found, downloading")
- download(BIGFONT_LIB, "/lib/bigfont.lua")
- print("Lib download complete, downlading fonts")
- for i=2,8 do download(getFontURL(i), "/lib/bigfont-size" .. tostring(i) .. ".hex") end
- status, bigfont = pcall(require, "bigfont")
- if (not status) or bigfont == nil then
- print("Couldn't install bigfont library, aborting.")
- os.exit()
- end
- print("BigFont library installed")
- end
- REFRESH_RATE = 5
- function get_followers()
- local r = net.request("https://api.twitch.tv/helix/users/follows?to_id=167165508&first=1", {}, {["Client-ID"]="74jgk3923ql6fw2cbb5835qcnb6jrt"}, "GET")
- res = ""
- for chunk in r do
- res = res .. chunk
- end
- local code, message, _ = getmetatable(r).__index.response()
- return json:decode(res)["total"], code, message
- end
- function time() return math.floor(os.time() / 100) end
- local h, w = gpu.getResolution()
- bigfont.load(8)
- local timestamp = time()
- local followers, code, message = get_followers()
- local start_followers = followers
- while true do
- if time() - timestamp >= REFRESH_RATE then
- timestamp = time()
- followers, code, message = get_followers()
- end
- term.clear() -- clear terminal(only works on print statements, resets cursor)
- gpu.fill(1, 1, w, h, " ") -- clear screen(actual complete clear)
- print("code: " .. tostring(code))
- print("msg: " .. tostring(message))
- print("Starting followers: " .. tostring(start_followers))
- bigfont.set(2, 14, "Gained Followers: " .. tostring(followers - start_followers), 8)
- print("Next refresh: " .. tostring(REFRESH_RATE - (time() - timestamp)))
- os.sleep(0.05)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement