From f7b83e98b7aadf568b2961e371c96d9c506ead21 Mon Sep 17 00:00:00 2001 From: Scritches Date: Wed, 18 Apr 2018 00:50:22 -0400 Subject: [PATCH] support for random sequences --- modules/oeis/oeis.js | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/modules/oeis/oeis.js b/modules/oeis/oeis.js index 7a23fdf..8debcc7 100644 --- a/modules/oeis/oeis.js +++ b/modules/oeis/oeis.js @@ -74,6 +74,28 @@ var OEIS = function(dbot) { if(!body.results) throw 'no-results'; return this.internalAPI.parseResult(body.results[0]); + }, + + 'getRandomSequenceA': async set => { + // This feature uses OEIS's 'webcam' which serves up random entries + // each time the page is refreshed. It appears to be the only way to get + // valid random entries from the database. The alternative is to just generate + // random A-numbers from the set of all A-numbers, but that seems dirty to me. + var body = await rp({ + url: this.webRoot + '/webcam', + qs: { + fromjavascript: 1, + q: 'keyword:' + set + } + }); + + // Find where the A-number is located + var i = body.indexOf('