turtle5204

Localized APIget

Mar 3rd, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.30 KB | None | 0 0
  1. function apiGet(page,args)
  2.     local curposx, curposy = term.getCursorPos()
  3.     if args then
  4.         utd = page.."?"..args
  5.     else
  6.         utd = page
  7.     end
  8.     sp = string.find(utd,"/")
  9.     if sp then
  10.         if #utd > sp then
  11.             domain = string.sub(utd,1,sp-1)
  12.             pageOS = string.sub(utd,sp+1,#utd)
  13.         else
  14.             domain = string.sub(utd,1,sp-1)
  15.             pageOS = "index"
  16.         end
  17.     else
  18.         domain = utd
  19.         pageOS = "index"
  20.     end
  21.     rednet.broadcast(pageOS,domain)
  22.     RTID = os.startTimer(6)
  23.     LSTID = os.startTimer(0.2)
  24.     lps = #"Loading" +1
  25.     write("Loading")
  26.     loadloops = 0
  27.     while true do
  28.         e,side,chan,rchan,msg,dist = os.pullEvent()
  29.         if e == "timer" and side == RTID then
  30.             print("Could not connect to site.")
  31.             return false
  32.         elseif e == "timer" and side == LSTID then
  33.             term.setCursorPos(-1+curposx+lps+loadloops,curposy)
  34.             if loadloops ~= 3 then
  35.                 write(".")
  36.             end
  37.             loadloops = loadloops +1
  38.             if loadloops == 4 then
  39.                 term.setCursorPos(curposx,curposy)
  40.                 write("Loading   ")
  41.                 loadloops = 0
  42.             end
  43.             LSTID = os.startTimer(0.2)
  44.         elseif e == "modem_message" and chan == os.getComputerID() then
  45.             if msg["nRecipient"] == os.getComputerID() then
  46.                 term.setCursorPos(curposx,curposy)
  47.                 write(string.rep(" "),#"Loading...")
  48.                 term.setCursorPos(curposx,curposy)
  49.                 return msg["message"]
  50.             end
  51.         end
  52.     end
  53. end
Advertisement
Add Comment
Please, Sign In to add comment