Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var request = require('request');
  2. var Twit = require('twit');
  3. var async = require('async');
  4. var T = new Twit({
  5.     consumer_key:         '' // Your Consumer Key
  6.   , consumer_secret:      '' // Your Consumer Secret
  7.   , access_token:         '' // Your Access Token
  8.   , access_token_secret:  '' // Your Access Token Secret
  9. });
  10.  
  11. var WORDNIKAPIKEY = '';
  12.  
  13. // GLOBAL VARS
  14. var randomWord; //get random word
  15. var rhymingWord; //get rhyming word
  16. var bogusDef; //get def of rhyming word
  17. var tweet; // combined random and bogusdef
  18.  
  19. function getWord(){
  20.     request('http://api.wordnik.com:80/v4/words.json/randomWord?hasDictionaryDef=false&minCorpusCount=0&maxCorpusCount=-1&minDictionaryCount=1&maxDictionaryCount=-1&minLength=5&maxLength=-1&api_key=' +
  21.     WORDNIKAPIKEY, function (err, resp, body) {
  22.         if (!err && resp.statusCode == 200) {
  23.             //console.log(body) // Show the HTML for the Google homepage.
  24.             var parsedData = JSON.parse(body);
  25.             console.log("Word: " + parsedData.word);
  26.    
  27.             // set random word
  28.             randomWord = parsedData.word;
  29.             getRhyme();
  30.         }
  31.     })
  32. }
  33.  
  34. // Get the rhyming word
  35. function getRhyme(){
  36.     request('http://api.wordnik.com:80/v4/word.json/' + randomWord +
  37.     '/relatedWords?useCanonical=false&relationshipTypes=rhyme&limitPerRelationshipType=10&api_key=' +
  38.     WORDNIKAPIKEY, function (err, resp, body) {
  39.         if (!err && resp.statusCode == 200) {
  40.             //console.log(body) // Show the HTML for the Google homepage.
  41.             var parsedData = JSON.parse(body);
  42.             console.log("Rhyme: " + parsedData[0].words[0]);
  43.    
  44.             // set rhyming word
  45.             rhymingWord = parsedData[0].words[0];
  46.             getDef();
  47.         }
  48.     })
  49. }
  50.  
  51. // GET THE SEXY DEFINITION BABY, BEACH BOD
  52. function getDef(){      
  53.     request('http://api.wordnik.com:80/v4/word.json/' + rhymingWord +
  54.     '/definitions?limit=200&includeRelated=true&sourceDictionaries=all&useCanonical=false&includeTags=false&api_key=' +
  55.     WORDNIKAPIKEY, function (err, resp, body) {
  56.         if (!err && resp.statusCode == 200) {
  57.             //console.log(body) // Show the HTML for the Google homepage.
  58.             var newnew = JSON.parse(body);
  59.             console.log("Definition: " + newnew[0].text);
  60.    
  61.             // set definition
  62.             bogusDef = parsedData[0].text;
  63.    
  64.             randomWord = randomWord.charAt(0).toUpperCase();
  65.             tweet = randomWord + ": " + bogusDef;
  66.             postStatus();
  67.         }
  68.     })
  69. }  
  70.  
  71. function postStatus(){
  72.     T.post('statuses/update', { status: tweet }, function(err, data, resp) {
  73.         if(err) {
  74.             console.log("There was a problem tweeting the message.", err);
  75.         }
  76.     });
  77.     console.log("status posted");
  78. }
  79. getWord();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement