Create a gist now

Instantly share code, notes, and snippets.

twitter webstream を監視するコード
Twitter = require 'ntwitter'
me = UserObject # { consumer_key: "", consumer_secret: "", access_token_key: "", access_token_secret: "" }
tw = new Twitter me
suicide = ->
process.exit 0
post = (msg) ->
msg = msg.slice 0, 140
console.log msg
url = "https://api.twitter.com/1.1/statuses/update.json"
tw.post url, {status: msg}, (->)
urlOf = (data) ->
"https://twitter.com/#{data.user.screen_name}/status/#{data.id_str}"
do ->
tw.stream 'user', (stream) ->
stream.on 'disconnect', (data) ->
console.log data.reason
do suicide
stream.on 'data', (data) ->
if (not data) or (not data.user) or (not data.text)
return
res = [
/live.nicovideo/
/nico.ms\/lv/
]
bl = data.entities.urls.some (url) -> res.some (re) -> re.test url.expanded_url
if bl
post "#{urlOf data}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment