Skip to content

Instantly share code, notes, and snippets.

@ikr7
Created April 21, 2015 11:31
Show Gist options
  • Save ikr7/1a8ba95e1217601c0fd5 to your computer and use it in GitHub Desktop.
Save ikr7/1a8ba95e1217601c0fd5 to your computer and use it in GitHub Desktop.
わこつ
require! {
child_process
twitter:Twitter
merge
}
tw = new Twitter {
consumer_key : process.env.IKR7GYAZO_CONSUMER_KEY
consumer_secret : process.env.IKR7GYAZO_CONSUMER_SECRET
access_token_key : process.env.IKR7GYAZO_ACCESS_TOKEN_KEY
access_token_secret: process.env.IKR7GYAZO_ACCESS_TOKEN_SECRET
}
share = (image, params, callback) ->
tw.post 'media/upload', media: image, (err, media) ->
if err
callback err
return
p = merge params, media_ids: media.media_id_string
tw.post 'statuses/update', p, (err, tweet) ->
if err
callback err
return
callback null, tweet
stream <- tw.stream 'user', _
data <- stream.on 'data', _
if data.text and data.text.match /\s*@ikr7gyazo\s+(.+)\s*/
imagesnap = child_process.spawn 'imagesnap', ['-d', 'FaceTime HD カメラ(内蔵)', '-']
convert = child_process.spawn 'convert', ['-', '-monochrome', '-sample', '20%', '-sample', '500%', '-']
imagesnap.stdout.pipe convert.stdin
bufs = []
convert.stdout.on \data, (ch) ->
bufs.push ch
<- convert.stdout.on \end, _
image = Buffer.concat bufs
err, tweet <- share image, {
status: "@#{data.user.screen_name}",
in_reply_to_status_id: data.id_str
}, _
console.log err, tweet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment