Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var request = require('request');
- var Twit = require('twit');
- var async = require('async');
- var T = new Twit({
- consumer_key: '' // Your Consumer Key
- , consumer_secret: '' // Your Consumer Secret
- , access_token: '' // Your Access Token
- , access_token_secret: '' // Your Access Token Secret
- });
- var WORDNIKAPIKEY = '';
- // GLOBAL VARS
- var randomWord; //get random word
- var rhymingWord; //get rhyming word
- var bogusDef; //get def of rhyming word
- var tweet; // combined random and bogusdef
- function getWord(){
- 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=' +
- WORDNIKAPIKEY, function (err, resp, body) {
- if (!err && resp.statusCode == 200) {
- //console.log(body) // Show the HTML for the Google homepage.
- var parsedData = JSON.parse(body);
- console.log("Word: " + parsedData.word);
- // set random word
- randomWord = parsedData.word;
- getRhyme();
- }
- })
- }
- // Get the rhyming word
- function getRhyme(){
- request('http://api.wordnik.com:80/v4/word.json/' + randomWord +
- '/relatedWords?useCanonical=false&relationshipTypes=rhyme&limitPerRelationshipType=10&api_key=' +
- WORDNIKAPIKEY, function (err, resp, body) {
- if (!err && resp.statusCode == 200) {
- //console.log(body) // Show the HTML for the Google homepage.
- var parsedData = JSON.parse(body);
- console.log("Rhyme: " + parsedData[0].words[0]);
- // set rhyming word
- rhymingWord = parsedData[0].words[0];
- getDef();
- }
- })
- }
- // GET THE SEXY DEFINITION BABY, BEACH BOD
- function getDef(){
- request('http://api.wordnik.com:80/v4/word.json/' + rhymingWord +
- '/definitions?limit=200&includeRelated=true&sourceDictionaries=all&useCanonical=false&includeTags=false&api_key=' +
- WORDNIKAPIKEY, function (err, resp, body) {
- if (!err && resp.statusCode == 200) {
- //console.log(body) // Show the HTML for the Google homepage.
- var newnew = JSON.parse(body);
- console.log("Definition: " + newnew[0].text);
- // set definition
- bogusDef = parsedData[0].text;
- randomWord = randomWord.charAt(0).toUpperCase();
- tweet = randomWord + ": " + bogusDef;
- postStatus();
- }
- })
- }
- function postStatus(){
- T.post('statuses/update', { status: tweet }, function(err, data, resp) {
- if(err) {
- console.log("There was a problem tweeting the message.", err);
- }
- });
- console.log("status posted");
- }
- getWord();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement