kd8lvt

Test Thingy

May 8th, 2015
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.63 KB | None | 0 0
  1. m = peripheral.find("monitor")
  2. --CONFIG--
  3. streamname="" --This should ALWAYS be lowercase, and within the quotes!
  4. streamname2="" --If this is empty then it just won't display two streams.
  5. function="" --This can be either "live" OR "followers". Live tells you if the streamer(s) is (are) live, Followers tells you the last five followers' names, this does NOT support two streams. It also needs a rather tall monitor.
  6. --CONFIG--
  7.  
  8. if not fs.exists('json') then
  9.         write("JSON API not found - Downloading")
  10.         shell.run("pastebin get 4nRg9CHU json")
  11. end
  12.  
  13. function live()
  14.         lstr = http.get("https://api.twitch.tv/kraken/streams/" .. streamname).readAll()
  15.         lobj = json.decode(lstr)
  16.         m.setCursorPos(1,1)
  17.  
  18.         if lobj.stream == nil then
  19.                 m.write(streamname)
  20.                 m.setCursorPos(1,4)
  21.                 m.write(streamname.." is offline.")
  22.         else
  23.         m.write(streamname)
  24.         m.setCursorPos(1,4)
  25.         m.write(streamname.." is live!")
  26.     end
  27. end
  28. function live2()
  29.         lstr = http.get("https://api.twitch.tv/kraken/streams/" .. streamname2).readAll()
  30.         lobj = json.decode(lstr)
  31.         m.setCursorPos(1,1)
  32.  
  33.         if lobj.stream == nil then
  34.                 m.write(streamname2)
  35.                 m.setCursorPos(1,7)
  36.                 m.write(streamname2.." is offline.")
  37.         else
  38.         m.write(streamname2)
  39.         m.setCursorPos(1,7)
  40.         m.write(streamname2.." is live!")
  41.     end
  42. end
  43.  
  44. function getFollowers()
  45.        
  46.         str = http.get("https://api.twitch.tv/kraken/channels/" .. streamname .. "/follows?limit=5").readAll()
  47.         obj = json.decode(str)
  48.         follower = json.encodePretty(obj.follows[1].user.name)
  49.     follower2 = json.encodePretty(obj.follows[2].user.name)
  50.     follower3 = json.encodePretty(obj.follows[3].user.name)
  51.     follower4 = json.encodePretty(obj.follows[4].user.name)
  52.     follower5 = json.encodePretty(obj.follows[5].user.name)
  53.    
  54.        
  55.         m.setCursorPos(1,5)    
  56.         m.write("Latest Follower: ")
  57.         m.write(follower)
  58.     m.setCursorPos(1,9)
  59.     m.write("Second To Latest Follower: ")
  60.         m.write(follower2)
  61.     m.setCursorPos(1,13)
  62.     m.write("Third To Latest Follower: ")
  63.         m.write(follower3)
  64.     m.setCursorPos(1,16)
  65.     m.write("Fourth To Latest Follower: ")
  66.         m.write(follower4)
  67.     m.setCursorPos(1,20)
  68.     m.write("Fifth To Latest Follower: ")
  69.         m.write(follower5)
  70.  
  71.         return follows
  72. end
  73.  
  74. while true do
  75.     if function == "live" then
  76.         if streamname2 == nil then
  77.             live()
  78.         else if streamname != nil then
  79.             live()
  80.             live2()
  81.         else
  82.             print("I'M SO CONFUSED!!!")
  83.         end
  84.     else if function == "followers"
  85.         getFollowers()
  86.     end
Advertisement
Add Comment
Please, Sign In to add comment