├── LICENSE ├── README.md └── send2kindle.coffee /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Peng Lv 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hubot-scripts 2 | My GitHub Hubot scripts. 3 | 4 | ## Setup 5 | 1. Setup Hubot per [GitHub Document](https://hubot.github.com/docs/) and integrate with whatever chatting tool you like. 6 | 2. Copy files from this repo to your hubot's scripts folder. 7 | 8 | ## send2kindle 9 | 1. Set up a mail server on your Linux, refer to this [article](https://easyengine.io/tutorials/linux/ubuntu-postfix-gmail-smtp/) for details. 10 | 2. Request a Readability [API Token](https://readability.com/developers/api). 11 | 3. Open `send2kindle.coffee` in your `scripts` folder and typein your readability token. 12 | 13 | Demo: 14 | ![](http://7sbn7z.com5.z0.glb.clouddn.com/hulk-bot.PNG) 15 | -------------------------------------------------------------------------------- /send2kindle.coffee: -------------------------------------------------------------------------------- 1 | module.exports = (robot) -> 2 | 3 | { spawn } = require 'child_process' 4 | readabilitytoken = "" 5 | kindleaddress = "" 6 | 7 | robot.hear /save (.*)/i, (res) -> 8 | res.send "Start to extract content from url" 9 | url = encodeURIComponent(res.match[1].split('#')[0]) 10 | 11 | robot.http("https://www.readability.com/api/content/v1/parser?url=" + url + "&token=" + readabilitytoken) 12 | .get() (err, resp, body) -> 13 | data = JSON.parse body 14 | fs = require('fs'); 15 | title = data.title || 'Hulk bot' 16 | now = new Date 17 | 18 | tmpfile = "~/tmp/" + now.getDay() + "-" + now.getHours() + "-" + now.getMinutes() + "-" + title.replace(/[^A-Za-z0-9]+/g,'-').toLowerCase() + ".html" 19 | if not data.content? 20 | res.send "Content undefined." 21 | return 22 | res.send "start to save content to local disk" 23 | fs.writeFile tmpfile, "" + data.content + "", (err) -> 24 | if err 25 | res.send err 26 | 27 | res.send "start to send " + title + " to kindle with file: " + tmpfile 28 | doing = spawn '/bin/bash', ['-c', "echo 'convert' | mail -s '" + title + "' -A " + tmpfile + " " + kindleaddress], {stdio: 'inherit'} 29 | res.send "finished." 30 | --------------------------------------------------------------------------------