SHOW:
|
|
- or go back to the newest paste.
1 | -- Written By Bacon_Donut | |
2 | -- http://twitch.tv/bacon_donut | |
3 | -- API call updated by @darkgoldblade on twitter | |
4 | ||
5 | -- View all my public pastebin codes at: | |
6 | -- http://pastebin.com/u/bacon_donut | |
7 | ||
8 | -- This is formatted to fit on a 1x3 wall of Advanced Monitors | |
9 | -- with an Advanced Computer on the left side. | |
10 | -- To get this to work you need to edit the streamid variable then run these four commands: | |
11 | ||
12 | -- label set SomeKindOfNameHere | |
13 | -- pastebin get 4nRg9CHU json | |
14 | -- pastebin get vhn1z23v startup | |
15 | -- startup | |
16 | ||
17 | -- ChangeLog: | |
18 | -- Feb 16, 2015 - @CoolAcid | |
19 | -- Added automatic download of JSON parser | |
20 | -- Fixed the offline streamer detection | |
21 | -- Added last follower option | |
22 | ||
23 | -- Twitch Name of the Streamer | |
24 | streamid = "Bacon_Donut" | |
25 | ||
26 | ||
27 | -- SleepTime is how often to grab new data. Set here to one minute. | |
28 | -- Set it too fast and twitch will flag you for spam | |
29 | -- and stop giving you data | |
30 | SleepTime = 60 | |
31 | ||
32 | if not fs.exists('json') then | |
33 | write("JSON API not found - Downloading") | |
34 | shell.run("pastebin get 4nRg9CHU json") | |
35 | end | |
36 | ||
37 | os.loadAPI("json") | |
38 | local m = peripheral.wrap("right") | |
39 | m.setCursorPos(1,1) | |
40 | ||
41 | function getFollowers() | |
42 | - | str = http.get("https://api.twitch.tv/kraken/channels/" .. streamid .. "/follows").readAll() |
42 | + | |
43 | str = http.get("https://api.twitch.tv/kraken/channels/" .. streamid .. "/follows?limit=1").readAll() | |
44 | obj = json.decode(str) | |
45 | follows = json.encodePretty(obj._total) | |
46 | ||
47 | m.setCursorPos(1,3) | |
48 | m.write("Twitch Followers: ") | |
49 | m.write(follows) | |
50 | ||
51 | return follows | |
52 | end | |
53 | ||
54 | function getFollower() | |
55 | ||
56 | str = http.get("https://api.twitch.tv/kraken/channels/" .. streamid .. "/follows?limit=1").readAll() | |
57 | obj = json.decode(str) | |
58 | follower = json.encodePretty(obj.follows[1].user.name) | |
59 | ||
60 | m.setCursorPos(1,5) | |
61 | m.write("Follower: ") | |
62 | m.write(follower) | |
63 | ||
64 | return follows | |
65 | end | |
66 | ||
67 | function getViewerCount() | |
68 | lstr = http.get("https://api.twitch.tv/kraken/streams/" .. streamid).readAll() | |
69 | lobj = json.decode(lstr) | |
70 | m.setCursorPos(1,1) | |
71 | ||
72 | ||
73 | if lobj.stream == nil then | |
74 | m.write(streamid) | |
75 | m.setCursorPos(1,4) | |
76 | m.write("Live Viewers: Offline") | |
77 | else | |
78 | live = json.encodePretty(lobj.stream.viewers) | |
79 | m.setBackgroundColor(colors.yellow) | |
80 | m.clear() | |
81 | m.write(streamid) | |
82 | m.setCursorPos(1,4) | |
83 | m.write("Live Viewers: ") | |
84 | - | m.setCursorPos(1,2) |
84 | + | |
85 | end | |
86 | ||
87 | return live | |
88 | end | |
89 | ||
90 | while true do | |
91 | m.setCursorPos(1,1) | |
92 | m.setBackgroundColor(colors.white) | |
93 | m.setTextColor(colors.blue) | |
94 | m.setTextScale(1) | |
95 | m.clear() | |
96 | ||
97 | m.write(streamid) | |
98 | m.setCursorPos(1,4) | |
99 | ||
100 | local status, live = pcall(function () getViewerCount() end) | |
101 | ||
102 | if status then | |
103 | -- do nothing | |
104 | else | |
105 | m.write("Live Viewers: Loading...") | |
106 | end | |
107 | ||
108 | local status, followsCount = pcall(function () getFollowers() end) | |
109 | ||
110 | m.setCursorPos(1,3) | |
111 | ||
112 | if status then | |
113 | -- do nothing | |
114 | else | |
115 | m.write("Twitch Follows: Loading...") | |
116 | end | |
117 | ||
118 | m.setCursorPos(1,5) | |
119 | ||
120 | local status, live = pcall(function () getFollower() end) | |
121 | ||
122 | if status then | |
123 | -- do nothing | |
124 | else | |
125 | m.write("Follower: Loading...") | |
126 | end | |
127 | ||
128 | ||
129 | ||
130 | sleep(SleepTime) | |
131 | end |