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 | -- Follower name added by @coolacid | |
5 | ||
6 | -- View all my public pastebin codes at: | |
7 | -- http://pastebin.com/u/bacon_donut | |
8 | ||
9 | -- This is formatted to fit on a 1x3 wall of Advanced Monitors | |
10 | -- with an Advanced Computer on the left side. | |
11 | -- To get this to work you need to edit the streamid variable then run these four commands: | |
12 | ||
13 | -- label set SomeKindOfNameHere | |
14 | -- pastebin get 4nRg9CHU json | |
15 | -- pastebin get vhn1z23v startup | |
16 | -- startup | |
17 | ||
18 | -- Twitch Name of the Streamer | |
19 | - | streamid = "Bacon_Donut" |
19 | + | streamid = "Soraffe" |
20 | ||
21 | ||
22 | -- SleepTime is how often to grab new data. Set here to one minute. | |
23 | -- Set it too fast and twitch will flag you for spam | |
24 | -- and stop giving you data | |
25 | SleepTime = 60 | |
26 | ||
27 | ||
28 | os.loadAPI("json") | |
29 | local m = peripheral.wrap("right") | |
30 | m.setCursorPos(1,1) | |
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("Last Follow: ") | |
40 | m.write(follower) | |
41 | ||
42 | return follows | |
43 | end | |
44 | ||
45 | function getFollowers() | |
46 | ||
47 | str = http.get("https://api.twitch.tv/kraken/channels/" .. streamid .. "/follows").readAll() | |
48 | obj = json.decode(str) | |
49 | follows = json.encodePretty(obj._total) | |
50 | ||
51 | m.setCursorPos(1,3) | |
52 | m.write("Twitch Followers: ") | |
53 | m.write(follows) | |
54 | ||
55 | return follows | |
56 | end | |
57 | ||
58 | function getViewerCount() | |
59 | lstr = http.get("https://api.twitch.tv/kraken/streams/" .. streamid).readAll() | |
60 | lobj = json.decode(lstr) | |
61 | ||
62 | m.setCursorPos(1,1) | |
63 | ||
64 | ||
65 | if live == "\"0\"" then | |
66 | m.write(streamid) | |
67 | m.setCursorPos(1,4) | |
68 | m.write("Live Viewers: Offline") | |
69 | else | |
70 | live = json.encodePretty(lobj.stream.viewers) | |
71 | m.setBackgroundColor(colors.yellow) | |
72 | m.clear() | |
73 | m.write(streamid) | |
74 | m.setCursorPos(1,4) | |
75 | m.write("Live Viewers: ") | |
76 | m.write(live) | |
77 | end | |
78 | ||
79 | return live | |
80 | end | |
81 | ||
82 | while true do | |
83 | m.setCursorPos(1,1) | |
84 | m.setBackgroundColor(colors.white) | |
85 | m.setTextColor(colors.blue) | |
86 | m.setTextScale(1) | |
87 | m.clear() | |
88 | ||
89 | m.write(streamid) | |
90 | m.setCursorPos(1,2) | |
91 | ||
92 | local status, live = pcall(function () getViewerCount() end) | |
93 | ||
94 | if status then | |
95 | -- do nothing | |
96 | else | |
97 | m.setCursorPos(1,4) | |
98 | m.write("Live Viewers: Loading...") | |
99 | end | |
100 | ||
101 | local status, followsCount = pcall(function () getFollowers() end) | |
102 | ||
103 | m.setCursorPos(1,3) | |
104 | ||
105 | if status then | |
106 | -- do nothing | |
107 | else | |
108 | ||
109 | m.write("Twitch Follows: Loading...") | |
110 | end | |
111 | ||
112 | local status, followsCount = pcall(function () getFollower() end) | |
113 | ||
114 | if status then | |
115 | -- do nothing | |
116 | else | |
117 | m.write("Last Follow: Loading...") | |
118 | end | |
119 | ||
120 | ||
121 | ||
122 | sleep(SleepTime) | |
123 | end |