├── README.md ├── bin └── cli.js ├── .gitignore ├── package.json ├── LICENSE └── lib └── arxote.js /README.md: -------------------------------------------------------------------------------- 1 | # arxote 2 | Grab from the arXiv and stuff into Evernote 3 | -------------------------------------------------------------------------------- /bin/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var Arx = require("../lib/arxote") 4 | , config = require("../config.json") // XXX this would need more flexibility 5 | , client = new Arx(config) 6 | ; 7 | 8 | // client.login(); 9 | 10 | client.load("http://arxiv.org/abs/1501.04115", function (err, $) { 11 | if (err) throw err; 12 | client.extract($, function (err, data) { 13 | if (err) throw err; 14 | console.log(data); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Commenting this out is preferred by some people, see 24 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- 25 | node_modules 26 | 27 | # Users Environment Variables 28 | .lock-wscript 29 | 30 | # Project stuff 31 | config.json 32 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "arxote", 3 | "version": "0.0.1", 4 | "description": "arXiv to Evernote", 5 | "main": "lib/arxote.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "bin": { 10 | "arxote": "./bin/cli.js" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/darobin/arxote.git" 15 | }, 16 | "keywords": [ 17 | "arXiv", 18 | "Evernote" 19 | ], 20 | "author": "Robin Berjon", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/darobin/arxote/issues" 24 | }, 25 | "homepage": "https://github.com/darobin/arxote", 26 | "dependencies": { 27 | "evernote": "^1.25.4", 28 | "superagent": "^0.21.0", 29 | "whacko": "^0.17.2" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Robin Berjon 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 | -------------------------------------------------------------------------------- /lib/arxote.js: -------------------------------------------------------------------------------- 1 | 2 | var Evernote = require("evernote").Evernote 3 | , crypto = require("crypto") 4 | , fs = require("fs") 5 | , sua = require("superagent") 6 | , whacko = require("whacko") 7 | ; 8 | 9 | function Arx (config) { 10 | for (var k in config) this[k] = config[k]; 11 | } 12 | 13 | Arx.prototype.login = function (cb) { 14 | if (!this.token) return cb(new Error("No token!")); 15 | console.log("token:", this.token); 16 | var client = new Evernote.Client({ token: this.token }); 17 | this.noteStore = client.getNoteStore(this.notesStoreURL); 18 | 19 | // https://www.evernote.com/shard/s5/notestore 20 | this.noteStore.listNotebooks(function (err, notebooks) { 21 | if (err) return cb(err); 22 | for (var i in notebooks) { 23 | if (notebooks[i].name === "to read") { 24 | this.notebookGuid = notebooks[i].guid; 25 | break; 26 | } 27 | } 28 | cb(); 29 | }); 30 | }; 31 | 32 | Arx.prototype.createNote = function (title, pdf, cb) { 33 | var note = new Evernote.Note(); 34 | note.title = title; 35 | note.notebookGuid = this.notebookGuid; 36 | var pdf = fs.readFileSync(pdf) 37 | , hash = pdf.toString("base64") 38 | , data = new Evernote.Data(); 39 | data.size = pdf.length; 40 | data.bodyHash = hash; 41 | data.body = pdf; 42 | var resource = new Evernote.Resource(); 43 | resource.mime = "application/pdf"; 44 | resource.data = data; 45 | note.resources = [resource]; 46 | var md5 = crypto.createHash("md5"); 47 | md5.update(pdf); 48 | var hashHex = md5.digest("hex"); 49 | 50 | note.content = '' + 51 | ''; 52 | this.noteStore.createNote(note, cb); // receives err, createdNote 53 | }; 54 | 55 | Arx.prototype.load = function (url, cb) { 56 | sua.get(url) 57 | .buffer(true) 58 | .end(function (err, res) { 59 | if (err) return cb(err); 60 | if (res.error) return cb(new Error(res.status)); 61 | cb(null, whacko.load(res.text)); 62 | }); 63 | }; 64 | 65 | Arx.prototype.extract = function ($, cb) { 66 | var data = {} 67 | , url = "http://arxiv.org" + $("a[accesskey='f']").attr("href") 68 | ; 69 | data.title = $("h1.title").text(); 70 | sua.get(url) 71 | // .buffer(true) 72 | .pipe() // XXX make a passthrough stream to debug 73 | .end(function (err, res) { 74 | // if (err) return cb(err); 75 | // if (res.error) return cb(new Error(res.status)); 76 | // data.pdf = res.text; 77 | // cb(null, data); 78 | }); 79 | }; 80 | 81 | module.exports = Arx; 82 | --------------------------------------------------------------------------------