Skip to content

Commit

Permalink
changed request to wiki api, fixed article name
Browse files Browse the repository at this point in the history
  • Loading branch information
coelacanth7 authored and dustinspecker committed Apr 17, 2018
1 parent f2f399c commit 90b15e4
Show file tree
Hide file tree
Showing 3 changed files with 6,870 additions and 11 deletions.
20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';
var cheerio = require('cheerio')
, got = require('got');
var got = require('got');

module.exports = function () {
return got('http://en.wikipedia.org/wiki/Special:Random').then(function (response) {
var $ = cheerio.load(response.body)
, title;

// use title to prevent dealing with formatting (<i></i>)
title = $('title').text();
return title.substr(0, title.indexOf(' - Wikipedia, the free encyclopedia'));
});
return got(
'https://en.wikipedia.org/w/api.php?action=query&list=random&rnlimit=1&format=json&origin=*&rnnamespace=0'
)
.then(function (response) {
return JSON.parse(response.body).query.random[0].title;
})
.catch(function (error) {
console.error(error);
});
};

0 comments on commit 90b15e4

Please sign in to comment.