Last active
February 26, 2020 22:04
-
-
Save andrew-t/33c41f89ed1580ca79b75133647fcf52 to your computer and use it in GitHub Desktop.
Bond Film Title Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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