-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
executable file
·33 lines (29 loc) · 885 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env node
var request = require('request-promise');
var track = 1;
var sorryMsg = 'Sorry, nothing to stream for now...';
if (process.argv[2] && process.argv[2].toLowerCase() == 'b') {
console.log("✨ Streaming track B✨ ");
track = 2;
} else {
console.log("✨ Streaming track A✨ ");
}
(function tick(stamp) {
request.get('http://www.streamtext.net/text-data.ashx?event=JSConf' + track + '&last=' + stamp + '&language=en')
.then(function(v) {
v = JSON.parse(v);
stamp = v.lastPosition;
if (v.i && v.i.length) {
process.stdout.write(v.i.map(function(v) {
return decodeURIComponent(v.d);
}).join(''));
}
})
.catch(function(err){
if(err.statusCode === 404) {
process.stdout.write(sorryMsg);
sorryMsg = '.';
}
})
.finally(setTimeout.bind({}, tick.bind({}, stamp), 1000));
})(null);