Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- A program written by 1lann --
- -- For computers --
- -- Made using CC 1.41 --
- url = "http://www.london2012.com/paralympics/medals/medal-count/"
- side = "back"
- 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")
- while string.find(rLine, "<span class=\"countryName\">") 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)
- if string.len(bInsert) > 11 then
- derp, bStart = string.find(rLine, "src=\"/imgml/flags/s/")
- bEnd = string.find(rLine, ".png\"", bStart+1)
- bStart = bStart+1
- bEnd = bEnd-1
- bInsert = string.sub(rLine, bStart, bEnd)
- end
- 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, scroll)
- while true do
- term.clear()
- term.setCursorPos(1,1)
- write(" +----------------------------------------------+")
- term.setCursorPos(1,2)
- write(" | London 2012 Paralympics Medals (By 1lann) |")
- term.setCursorPos(1,3)
- write(" | Rank | Country |Gold |Silver|Bronze|Total|")
- term.setCursorPos(1,4)
- write(" +------+-------------+-----+------+------+-----+")
- i = 0
- for b = scroll, scroll+14 do
- i = i + 1
- term.setCursorPos(2,i+4)
- write("| " .. rank[b])
- term.setCursorPos(9,i+4)
- write("| " .. country[b])
- term.setCursorPos(23,i+4)
- write("| " .. gold[b])
- term.setCursorPos(29,i+4)
- write("| " .. silver[b])
- term.setCursorPos(36,i+4)
- write("| " .. bronze[b])
- term.setCursorPos(43,i+4)
- write("| " .. total[b])
- term.setCursorPos(49, i+4)
- write("|")
- end
- term.setCursorPos(1, 19)
- write(" +------+-------------+-----+------+------+-----+")
- while true do
- event, key = os.pullEvent()
- if event == "key" then
- if key == 200 and scroll ~= 1 then
- scroll = scroll - 1
- break
- elseif key == 208 and scroll ~= #country - 14 then
- scroll = scroll + 1
- break
- elseif key == 18 then
- term.clear()
- return
- end
- end
- end
- end
- 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()
- scroll = 1
- drawGUI(rank, country, gold, silver, bronze, total, scroll)
- end
- local code = nil
- term.setCursorBlink(false)
- print("Press E to Exit")
- textutils.slowPrint("Downloading results...")
- sTimer = os.startTimer(45)
- http.request(url)
- while true do
- event, a, code = os.pullEvent()
- if event == "http_failure" then
- term.clearLine()
- print("Connection failed!")
- fail = true
- break
- elseif event == "http_success" then
- fail = false
- break
- elseif event == "timer" and a == sTimer then
- print("Connection timed out!")
- fail = true
- break
- end
- end
- if code == nil and fail == false then
- print("Page not found!")
- fail = true
- end
- if not fail then
- load(false, code)
- else
- error()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement