Skip to content

Instantly share code, notes, and snippets.

@cympfh
Created February 6, 2016 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cympfh/54260f85da7e6a470bb2 to your computer and use it in GitHub Desktop.
Save cympfh/54260f85da7e6a470bb2 to your computer and use it in GitHub Desktop.
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