Skip to content

Instantly share code, notes, and snippets.

@andrew-t
Last active February 26, 2020 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrew-t/33c41f89ed1580ca79b75133647fcf52 to your computer and use it in GitHub Desktop.
Save andrew-t/33c41f89ed1580ca79b75133647fcf52 to your computer and use it in GitHub Desktop.
Bond Film Title Generator
const fetch = require('node-fetch'),
cheerio = require('cheerio');
fetch('https://en.wikipedia.org/wiki/English-language_idioms')
.then(res => res.text())
.then(html => cheerio.load(html))
.then($ => {
const t = $('#mw-content-text .wikitable.sortable td:first-child');
for (let i = 0; i < 50; ++i) {
const words = $(t[rnd(t)]).text().split(' '),
r = Math.random();
if (r < 0.525) raw('die');
if (r > 0.475) raw('gold');
console.log(words.map(w => w.replace(/^./, x => x.toUpperCase())).join(' '));
function raw(w) { words[rnd(words)] = w; }
}
});
function rnd(a) { return Math.floor(Math.random() * a.length); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment