Skip to content

Commit 57e81d5

Browse files
committed
add twitter stream
1 parent 463280d commit 57e81d5

File tree

5 files changed

+34
-4
lines changed

5 files changed

+34
-4
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ You are GIF JOCKEY!!!!
3030
% foreman start
3131
```
3232

33+
## Configuation
34+
35+
```
36+
REDISTOGO_URL=...
37+
CONSUMER_KEY=...
38+
CONSUMER_SECRET=...
39+
ACCESS_TOKEN=...
40+
ACCESS_TOKEN_SECRET=...
41+
HASH_TAG=#kosendj
42+
```
43+
3344
## Usage
3445

3546
* for Users -> http://gjbu.herokuapp.com/usage ([Source](https://github.com/kosendj/gj/blob/master/views/usage.jade))

index.coffee

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ app.get '/bpm', require('./lib/bpm').get
4040
app.get '/usage', (req, res)-> res.render 'usage'
4141

4242
io.on 'connection', require './lib/socket'
43+
require './lib/twitter'
4344

4445
port = if process.env.PORT
4546
parseInt(process.env.PORT, 10)

lib/twitter.coffee

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Twit = require 'twit'
2+
io = process.globals.io
3+
4+
twitter = new Twit
5+
consumer_key: process.env.CONSUMER_KEY
6+
consumer_secret: process.env.CONSUMER_SECRET
7+
access_token: process.env.ACCESS_TOKEN
8+
access_token_secret: process.env.ACCESS_TOKEN_SECRET
9+
10+
replaceHashtag = new RegExp process.env.HASH_TAG, 'g'
11+
12+
stream = twitter.stream 'statuses/filter',
13+
track: process.env.HASH_TAG
14+
15+
stream.on 'tweet', (tweet)->
16+
io.emit 'tweet',
17+
text: tweet.text.replace replaceHashtag, ''

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"redis": "^0.12.1",
2020
"request": "^2.40.0",
2121
"socket.io": "^1.0.6",
22-
"stylus": "^0.49.3"
22+
"stylus": "^0.49.3",
23+
"twit": "^1.1.18"
2324
}
2425
}

public/js/screen.coffee

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ interrupt = (url)->
7474
main.update()
7575
, duration
7676

77-
commentAdd = (body)->
77+
tweetAdd = (tweet)->
7878
top = $('.comment').length * 40
7979
top -= $('.commentContainer').height() while top > $('.commentContainer').height()
80-
$("<p>").text(body)
80+
$("<p>").text(tweet.text)
8181
.addClass('comment')
8282
.appendTo $('.commentContainer')
8383
.css
@@ -115,5 +115,5 @@ socket.on 'added', -> if !main.$get('lock') then main.update()
115115
socket.on 'choose', -> if !main.$get('lock') then main.update()
116116
socket.on 'bpm', (bpm)-> main.$data.bpm = bpm
117117
socket.on 'djadded', interrupt
118-
socket.on 'comment', commentAdd
118+
socket.on 'tweet', tweetAdd
119119
socket.on 'name', (name)-> main.$data.name = name

0 commit comments

Comments
 (0)