DrFair

Real time http get

Apr 7th, 2014
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. monitorSide = "top"
  2. monitorScale = 1
  3.  
  4. if not fs.exists( "fui" ) then
  5. print( "Performing first time setup." )
  6. shell.run( "pastebin","get", "306Ns1qg", "fui" )
  7. print("Finished. Please run program again.")
  8. error()
  9. end
  10.  
  11. monitor = peripheral.wrap( monitorSide )
  12. monitor.setTextScale( monitorScale )
  13. os.loadAPI("fui")
  14. fui.setMonitorSide( monitorSide )
  15. os.sleep(5)
  16. w,h = fui.getSize()
  17. line = {}
  18.  
  19. function getRealTime()
  20. site = http.get("http://www.timeanddate.com/worldclock/denmark/copenhagen")
  21. data = site.readAll()
  22. if data then
  23. timeStart = string.find( data, "class=h1>" )
  24. timeEnd = string.find( data, "</span>", timeStart)
  25. zoneStart = string.find( data, "title=", timeEnd )
  26. zoneStart = string.find( data, ">", zoneStart )
  27. zoneEnd = string.find( data, "</a>", zoneStart)
  28. dateStart = string.find( data, "id=ctdat>" )
  29. dateEnd = string.find( data, "</span>", dateStart)
  30. if timeStart ~= nil then
  31. time = string.sub( data, timeStart + 9, timeEnd - 1)
  32. zone = string.sub( data, zoneStart + 1, zoneEnd - 1)
  33. date = string.sub( data, dateStart + 9, dateEnd - 1)
  34. end
  35. return true
  36. end
  37. return false
  38. end
  39.  
  40. while true do
  41. text = getRealTime()
  42. getRealTime()
  43. fui.clear()
  44. fui.drawAlignText( "Welcome to", "mid", w/2+1, 2, "white" )
  45. fui.drawAlignText( "Fair's base", "mid", w/2+1, 4, "cyan" )
  46. fui.drawAlignText( "Current realtime:", "mid", w/2+1, 6, "white" )
  47. fui.drawAlignText( time..", "..zone, "mid", w/2+1, 8, "lightgray" )
  48. fui.drawAlignText( date, "mid", w/2+1, 9, "lightgray" )
  49. fui.drawAlignText( "Feel free to look around!", "mid", w/2+1, 11, "white" )
  50. os.sleep(0.8)
  51. end
Advertisement
Add Comment
Please, Sign In to add comment