├── .gitignore ├── README.md ├── LICENSE.txt └── metaphor.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Metaphor-a-Minute! 2 | ========== 3 | 4 | Requires [node](http://nodejs.org/) and [npm](http://npmjs.org/). You also need a Twitter App access token, consumer key, and associated secrets: https://dev.twitter.com/apps/new 5 | 6 | Finally, you need a Wordnik API key, which you can apply for here: http://developer.wordnik.com/ 7 | 8 | (You'll need to add all that info to metaphor.js before running the program, otherwise Wordnik and Twitter won't play nice. Don't worry, it's all commented.) 9 | 10 | > npm install node-restclient@0.0.1 11 | 12 | > npm install twit@1.1.6 13 | 14 | > npm install express@2.5.9 15 | 16 | > node metaphor.js 17 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Darius Kazemi 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /metaphor.js: -------------------------------------------------------------------------------- 1 | var restclient = require('node-restclient'); 2 | var Twit = require('twit'); 3 | var app = require('express').createServer(); 4 | 5 | // I deployed to Nodejitsu, which requires an application to respond to HTTP requests 6 | // If you're running locally you don't need this, or express at all. 7 | app.get('/', function(req, res){ 8 | res.send('Hello world.'); 9 | }); 10 | app.listen(3000); 11 | 12 | // insert your twitter app info here 13 | var T = new Twit({ 14 | consumer_key: '', 15 | consumer_secret: '', 16 | access_token: '', 17 | access_token_secret: '' 18 | }); 19 | 20 | var statement = ""; 21 | 22 | // insert your Wordnik API info below 23 | var getNounsURL = "http://api.wordnik.com/v4/words.json/randomWords?" + 24 | "minCorpusCount=1000&minDictionaryCount=10&" + 25 | "excludePartOfSpeech=proper-noun,proper-noun-plural,proper-noun-posessive,suffix,family-name,idiom,affix&" + 26 | "hasDictionaryDef=true&includePartOfSpeech=noun&limit=2&maxLength=12&" + 27 | "api_key=______YOUR_API_KEY_HERE___________"; 28 | 29 | var getAdjsURL = "http://api.wordnik.com/v4/words.json/randomWords?" + 30 | "hasDictionaryDef=true&includePartOfSpeech=adjective&limit=2&" + 31 | "minCorpusCount=100&api_key=______YOUR_API_KEY_HERE___________"; 32 | 33 | 34 | function makeMetaphor() { 35 | statement = ""; 36 | restclient.get(getNounsURL, 37 | function(data) { 38 | first = data[0].word.substr(0,1); 39 | first2 = data[1].word.substr(0,1); 40 | article = "a"; 41 | if (first === 'a' || 42 | first === 'e' || 43 | first === 'i' || 44 | first === 'o' || 45 | first === 'u') { 46 | article = "an"; 47 | } 48 | article2 = "a"; 49 | if (first2 === 'a' || 50 | first2 === 'e' || 51 | first2 === 'i' || 52 | first2 === 'o' || 53 | first2 === 'u') { 54 | article2 = "an"; 55 | } 56 | 57 | var connector = "is"; 58 | switch (Math.floor(Math.random()*12)) { 59 | case 0: 60 | connector = "of"; 61 | break; 62 | case 1: 63 | connector = "is"; 64 | break; 65 | case 2: 66 | connector = "is"; 67 | break; 68 | case 3: 69 | connector = "considers"; 70 | break; 71 | case 4: 72 | connector = "is"; 73 | break; 74 | } 75 | 76 | statement += article + " " + data[0].word + " " + connector + " " + article2 + " " + data[1].word; 77 | 78 | restclient.get( 79 | getAdjsURL, 80 | function(data) { 81 | var connector = " and"; 82 | switch (Math.floor(Math.random()*8)) { 83 | case 0: 84 | connector = ", not"; 85 | break; 86 | case 1: 87 | connector = ", yet"; 88 | break; 89 | case 2: 90 | connector = " but"; 91 | break; 92 | case 3: 93 | connector = ","; 94 | break; 95 | case 4: 96 | connector = ", but not"; 97 | break; 98 | } 99 | output = data[0].word + connector + " " + data[1].word; 100 | statement = statement + ": " + output; 101 | console.log(statement); 102 | T.post('statuses/update', { status: statement}, function(err, reply) { 103 | console.log("error: " + err); 104 | console.log("reply: " + reply); 105 | }); 106 | } 107 | ,"json"); 108 | } 109 | ,"json"); 110 | } 111 | 112 | function favRTs () { 113 | T.get('statuses/retweets_of_me', {}, function (e,r) { 114 | for(var i=0;i