Last active
August 29, 2015 14:18
-
-
Save nulltask/f9cd06a6a6365ee88754 to your computer and use it in GitHub Desktop.
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
| var cheerio = require('cheerio'); | |
| var request = require('superagent'); | |
| var target = 'http://store.apple.com/jp/mac'; | |
| var hooks = [ | |
| 'https://hooks.slack.com/services/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', | |
| 'https://hooks.slack.com/services/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' | |
| ]; | |
| var count = 0; | |
| setTimeout(function() { | |
| var callee = arguments.callee; | |
| request | |
| .get(target) | |
| .end(function(err, res) { | |
| var $ = cheerio.load(res.text); | |
| var down = $('[alt="We\'ll be back soon"]').length; | |
| var soon = $('.macbook-bb-201501 .tagline.fwl').text(); | |
| var released = soon.trim() != 'まもなく登場。'; | |
| var text = released | |
| ? '新しい MacBook が登場した模様。買うんだ! :tada: ' + target | |
| : 'まだ新しい MacBook 出てないっぽい。'; | |
| if (down) text = 'We\'ll back soon.'; | |
| text += ' ' + (new Date()).toString(); | |
| console.log('step', count); | |
| setTimeout(callee, 1000 * 60); | |
| if (!released && 0 != count++ % 60) return; | |
| hooks.forEach(function(hook) { | |
| request | |
| .post(hook) | |
| .send({ | |
| channel: '#canweordermacbookyet', | |
| icon_url: 'http://images.apple.com/v/macbook/b/overview/images/overview_usb_macbook_large.jpg', | |
| username: '新しい MacBook 登場監視するマン', | |
| text: text | |
| }) | |
| .end(function(err, res) { | |
| process.stdout.write('.'); | |
| }); | |
| }); | |
| }); | |
| }); |
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
| { | |
| "dependencies": { | |
| "cheerio": "^0.19.0", | |
| "superagent": "^1.1.0" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment