Skip to content

Commit

Permalink
Merge pull request #3 from esteedqueen/modify-api-query
Browse files Browse the repository at this point in the history
Modifies API query to optimize selection of random name
  • Loading branch information
dadepo authored May 14, 2018
2 parents 6c423c9 + b1597e3 commit ebccb47
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions components/tweeter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ var secret = {
// make a new twitter object that takes in the api keys
var Twitter = new TwitterPackage(secret);

// get reques to yoruba names api
var randomCount = _.random(1, 100)
var randomPage = _.random(1, 62) // 62 is the max number of pages of 100 names/content available via the API

// get request to yoruba names api
function retrieveTweet () {
const http = require("http");
const url =
"http://www.yorubaname.com/v1/names?count=5000";
`http://www.yorubaname.com/v1/names?page=${randomPage}&count=${randomCount}&state=PUBLISHED`;
http.get(url, res => {
res.setEncoding("utf8");
let body = "";
Expand All @@ -33,10 +36,10 @@ function retrieveTweet () {
body = JSON.parse(body);

// pick a random name from JSON repsonse without repeating
var randomName = _.shuffle(body)[0];
var randomName = _.sample(body);
console.log(randomName);
// create link for random name
var linkBack = "http://www.yorubaname.com/entries/" + randomName["name"];
var linkBack = `http://www.yorubaname.com/entries/${randomName["name"]}`;
console.log(randomName["name"]+ "\n" + randomName["meaning"] + "\n" + linkBack);

// posting to twitter
Expand Down

0 comments on commit ebccb47

Please sign in to comment.