Advertisement
Guest User

ar

a guest
Sep 2nd, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.08 KB | None | 0 0
  1. local component = require("component")
  2. local net = require("internet")
  3. local gpu = component.gpu
  4. local term = require("term")
  5. local event = require("event")
  6. local computer = require("computer")
  7. local unicode = require("unicode")
  8. local interval = 60
  9. local id, shortik, resp
  10.  
  11. gpu.setResolution(27, 10)
  12. gpu.setBackground(0xFFFFFF)
  13. gpu.setForeground(0x000000)
  14. gpu.fill(1, 1, 27, 10, " ")
  15. term.setCursorBlink(false)
  16.  
  17. function onTimer()
  18.   term.clear()
  19.  
  20.   resp = net.request("http://shortiki.com/export/api.php?format=json&type=random&amount=1")
  21.  
  22.   for line in resp do
  23.     line = string.gsub(line, '\\"', unicode.char(0x0027))
  24.     id = string.match(line, 'id": "([^"]+)"')
  25.     shortik = string.match(line, 'content": "([^"]+)"')
  26.     shortik = string.gsub(shortik, unicode.char(0x0027), '"')
  27.     term.write("Цитата номер "..id.."\n")
  28.     term.setCursor(1, 3)
  29.     term.write(shortik.."\n\n", true)
  30.     term.setCursor(1, 10)
  31.     term.write("Источник: shortiki.com")
  32.   end
  33.  
  34. end
  35.  
  36. onTimer()
  37. event.timer(interval, onTimer, math.huge)
  38.  
  39. while true do
  40.   os.sleep(0)
  41.   computer.freeMemory()
  42.   event.pull()
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement