Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- A program written by 1lann --
- -- FOR MONITORS ONLY --
- -- MONITOR MUST BE 8 WIDE --
- url = "http://www.london2012.com/paralympics/medals/medal-count/"
- side = "back"
- noObjects = 25
- local function getResults()
- local country = {}
- local rank = {}
- local gold = {}
- local silver = {}
- local bronze = {}
- local total = {}
- local bStart = nil
- local bEnd = nil
- local bInsert = nil
- local derp = nil
- local rLine = nil
- f = io.open("/.tmpresults")
- for i = 1, 30 do
- f:read("*l")
- end
- local rLine = f:read("*l")
- for i = 1, noObjects do
- derp, bStart = string.find(rLine, "<td class=\"position c\">")
- bEnd = string.find(rLine, "</td>", bStart+1)
- bStart = bStart+1
- bEnd = bEnd-1
- bInsert = string.sub(rLine, bStart, bEnd)
- table.insert(rank, bInsert)
- derp, bStart = string.find(rLine, "<span class=\"countryName\">")
- bEnd = string.find(rLine, "</span>", bStart+1)
- bStart = bStart+1
- bEnd = bEnd-1
- bInsert = string.sub(rLine, bStart, bEnd)
- table.insert(country, bInsert)
- derp, bStart = string.find(rLine, "<td class=\"gold c\">")
- bEnd = string.find(rLine, "</td>", bStart+1)
- bStart = bStart+1
- bEnd = bEnd-1
- bInsert = string.sub(rLine, bStart, bEnd)
- table.insert(gold, bInsert)
- derp, bStart = string.find(rLine, "<td class=\"silver c\">")
- bEnd = string.find(rLine, "</td>", bStart+1)
- bStart = bStart+1
- bEnd = bEnd-1
- bInsert = string.sub(rLine, bStart, bEnd)
- table.insert(silver, bInsert)
- derp, bStart = string.find(rLine, "<td class=\"bronze c\">")
- bEnd = string.find(rLine, "</td>", bStart+1)
- bStart = bStart+1
- bEnd = bEnd-1
- bInsert = string.sub(rLine, bStart, bEnd)
- table.insert(bronze, bInsert)
- f:read("*l")
- f:read("*l")
- rLine = f:read("*l")
- derp, bStart = string.find(rLine, "<td class=\"total c\">")
- bEnd = string.find(rLine, "</td>", bStart+1)
- bStart = bStart+1
- bEnd = bEnd-1
- bInsert = string.sub(rLine, bStart, bEnd)
- table.insert(total, bInsert)
- end
- f:close()
- return rank, country, gold, silver, bronze, total
- end
- local function drawGUI(rank, country, gold, silver, bronze, total)
- mon.clear()
- mon.setCursorPos(1,2)
- mon.write(" +-------------------------------------------------------------------------+")
- mon.setCursorPos(1,3)
- mon.write(" | London 2012 Olympics: Top " .. noObjects .. " Countries (Updated every 5 minutes) |")
- mon.setCursorPos(1,4)
- mon.write(" | Rank | Country |Gold |Silver|Bronze|Total|")
- mon.setCursorPos(1,5)
- mon.write(" +------+----------------------------------------+-----+------+------+-----+")
- for i = 1, #country do
- mon.setCursorPos(2,i+5)
- mon.write("| " .. rank[i])
- mon.setCursorPos(9,i+5)
- mon.write("| " .. country[i])
- mon.setCursorPos(50,i+5)
- mon.write("| " .. gold[i])
- mon.setCursorPos(56,i+5)
- mon.write("| " .. silver[i])
- mon.setCursorPos(63,i+5)
- mon.write("| " .. bronze[i])
- mon.setCursorPos(70,i+5)
- mon.write("| " .. total[i])
- mon.setCursorPos(76, i+5)
- mon.write("|")
- end
- mon.setCursorPos(1, #country+6)
- mon.write(" +------+----------------------------------------+-----+------+------+-----+")
- end
- local function load(fail, code)
- if not fail then
- f = io.open("/.tmpresults", "w")
- f:write(code:readAll())
- f:close()
- code:close()
- end
- local country = {}
- local rank = {}
- local gold = {}
- local silver = {}
- local bronze = {}
- local total = {}
- rank, country, gold, silver, bronze, total = getResults()
- drawGUI(rank, country, gold, silver, bronze, total)
- print("Waiting...")
- if fail then
- sleep(30)
- else
- sleep(300)
- end
- end
- local code = nil
- mon = peripheral.wrap(side)
- print("2012 London Olympic Games Scoreboard")
- print("For 8 wide monitors only!")
- print("Made by 1lann")
- term.setCursorBlink(false)
- mon.setCursorBlink(false)
- while true do
- textutils.slowPrint("Downloading results...")
- mon.setTextScale(1)
- mon.clear()
- mon.setCursorPos(1,1)
- os.startTimer(45)
- http.request(url)
- while true do
- event, a, code = os.pullEvent()
- if event == "http_failure" or event == "timer" then
- term.clearLine()
- print("Connection failed!")
- fail = true
- break
- elseif event == "http_success" then
- fail = false
- break
- end
- end
- if code == nil and fail == false then
- term.clearLine()
- print("Page not found!")
- fail = true
- end
- if not fail then
- load(false, code)
- elseif fs.exists("/.tmpresults") then
- print("Failure warning")
- load(fail, code)
- else
- print("Retrying in 30 seconds...")
- sleep(30)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement