Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifies API query to optimize selection of random name #3

Merged
merged 1 commit into from
May 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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