Advertisement
kd8lvt

twitchapi

Nov 6th, 2015
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.86 KB | None | 0 0
  1. function isjsoninstalled()
  2.   if fs.exists("json") then
  3.     return true
  4.   else
  5.     print("JSON API Not found! Downloading...")
  6.     resp = http.get("http://pastebin.com/raw.php?i=4nRg9CHU")
  7.     if resp then
  8.       handler = io.open("json","w")
  9.       handler:write(resp.readAll())
  10.       handler:close()
  11.     end
  12.     print("Finished downloading JSON API!")
  13.     return true
  14.   end
  15. end
  16.  
  17. function live(streamid,colorLive,colorNotLive)
  18.   isjsoninstalled()
  19.   os.loadAPI("json")
  20.   str = http.get("https://api.twitch.tv/kraken/streams/"..streamid).readAll()
  21.   obj = json.decode(str)
  22.   stream = obj.stream
  23.   if stream ~= null then
  24.     term.setTextColor(colorLive)
  25.     print(streamid.." is live!")
  26.     term.setTextColor(colors.white)
  27.   else
  28.     term.setTextColor(colorNotLive)
  29.     print(streamid.." is not live!")
  30.     term.setTextColor(colors.white)
  31.   end
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement