Created
April 22, 2016 02:17
-
-
Save polidog/8d070c5efcceaea9a3cb272c65c28c6c to your computer and use it in GitHub Desktop.
nightmare+hubot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Nightmare = require 'nightmare' | |
request = require 'request' | |
fs = require 'fs' | |
Gyazo = require 'gyazo-api' | |
nightmare = Nightmare() | |
url = process.env.HATENA_COUNT_URL | |
filename = "./ss.png" | |
client = new Gyazo(process.env.GYAZO_TOKEN) | |
module.exports = (robot) -> | |
robot.respond /記念日/i, (msg)-> | |
nightmare.goto(url) | |
.screenshot(filename, { | |
x: 0, | |
y: 66, | |
height: 283, | |
width: 502 | |
}) | |
.evaluate => | |
return document.querySelector('meta[name="twitter:title"]').getAttribute("content") + document.querySelector('meta[name="twitter:description"]').getAttribute("content") | |
.end() | |
.then (title)=> | |
client.upload(filename) | |
.then (res) => | |
fs.unlink(filename) | |
console.log "#{title}です" | |
robot.emit 'slack.attachment', | |
message: msg.message | |
content: | |
text: title | |
color: "#36a64f" | |
author_name: "#{title}です" | |
image_url: res.data.permalink_url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment