kd8lvt

Twitch Status

Aug 18th, 2015
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.85 KB | None | 0 0
  1. -- Twitch Name of the Streamer
  2. streamid = "CHOOBTASTIC"
  3.  
  4.  
  5. -- SleepTime is how often to grab new data. Set here to one minute.
  6. -- Set it too fast and twitch will flag you for spam
  7. -- and stop giving you data
  8. SleepTime = 60
  9.  
  10. if not fs.exists('json') then
  11.         write("JSON API not found - Downloading")
  12.         shell.run("pastebin get 4nRg9CHU json")
  13. end
  14.  
  15. os.loadAPI("json")
  16. local m = peripheral.find("monitor")
  17. m.setCursorPos(1,1)
  18.  
  19. function getFollowers()
  20.  
  21.         str = http.get("https://api.twitch.tv/kraken/channels/" .. streamid .. "/follows?limit=1").readAll()
  22.         obj = json.decode(str)
  23.         follows = json.encodePretty(obj._total)
  24.  
  25.         m.setCursorPos(1,3)    
  26.         m.write("Twitch Followers: ")
  27.         m.write(follows)
  28.  
  29.         return follows
  30. end
  31.  
  32. function getFollower()
  33.  
  34.         str = http.get("https://api.twitch.tv/kraken/channels/" .. streamid .. "/follows?limit=1").readAll()
  35.         obj = json.decode(str)
  36.         follower = json.encodePretty(obj.follows[1].user.name)
  37.  
  38.         m.setCursorPos(1,5)    
  39.         m.write("Follower: ")
  40.         m.write(follower)
  41.  
  42.         return follows
  43. end
  44.  
  45. function getViewerCount()
  46.         lstr = http.get("https://api.twitch.tv/kraken/streams/" .. streamid).readAll()
  47.         lobj = json.decode(lstr)
  48.         m.setCursorPos(1,1)
  49.  
  50.  
  51.         if lobj.stream == nil then
  52.                 m.write(streamid)
  53.                 m.setCursorPos(1,4)
  54.                 m.write("Live Viewers: Offline")
  55.         else
  56.                 live = json.encodePretty(lobj.stream.viewers)
  57.                 m.setBackgroundColor(colors.black)
  58.                 m.clear()
  59.                 m.write(streamid)
  60.                 m.setCursorPos(1,4)
  61.                 m.write("Live Viewers: ")
  62.                 m.write(live)          
  63.         end
  64.  
  65.         return live
  66. end
  67.  
  68. while true do
  69.         m.setCursorPos(1,1)
  70.         m.setBackgroundColor(colors.white)
  71.         m.setTextColor(colors.blue)
  72.         m.setTextScale(1)
  73.         m.clear()
  74.  
  75.         m.write(streamid)
  76.         m.setCursorPos(1,4)
  77.  
  78.         local status, live = pcall(function () getViewerCount() end)
  79.  
  80.         if status then
  81.                 -- do nothing
  82.         else
  83.                 m.write("Live Viewers: Loading...")
  84.         end
  85.  
  86.         local status, followsCount = pcall(function () getFollowers() end)
  87.  
  88.         m.setCursorPos(1,3)    
  89.  
  90.         if status then        
  91.                 -- do nothing
  92.         else          
  93.                 m.write("Twitch Follows: Loading...")
  94.         end
  95.  
  96.         m.setCursorPos(1,5)    
  97.  
  98.         local status, live = pcall(function () getFollower() end)
  99.  
  100.         if status then
  101.                 -- do nothing
  102.         else
  103.                 m.write("Follower: Loading...")
  104.         end
  105.     m.setCursorPos(1,7)
  106.     m.write("Thanks to all our viewers and followers! <3")
  107.  
  108.  
  109.         sleep(SleepTime)
  110. end
Advertisement
Add Comment
Please, Sign In to add comment