From 0b4bd72b3ad27eda91e6ac024cb1e660ed898b7a Mon Sep 17 00:00:00 2001 From: iotcat Date: Mon, 2 Mar 2020 11:12:39 +0000 Subject: [PATCH] uk --- test-uk.js | 5 +++++ uk.js | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 test-uk.js create mode 100644 uk.js diff --git a/test-uk.js b/test-uk.js new file mode 100644 index 0000000..1668cd7 --- /dev/null +++ b/test-uk.js @@ -0,0 +1,5 @@ +const coro = require('./uk.js'); + +(async () => { + console.log(await coro()); +})() \ No newline at end of file diff --git a/uk.js b/uk.js new file mode 100644 index 0000000..d5a8536 --- /dev/null +++ b/uk.js @@ -0,0 +1,38 @@ +/* coro-py-uk +* +* By iotcat (https://iotcat.me) +* MIT Licensed +* +*/ +module.exports = async (params) => { + + var o_params = { + reg: /negative\sand\s(\S*)\spositive/, + url: 'https://www.gov.uk/guidance/coronavirus-covid-19-information-for-the-public#number-of-cases' + } + + Object.assign(o_params, params); + + var o = []; + + const request = require('request'); + + + return new Promise((resolve, reject) => { + request(o_params.url, (err, res, body) => { + if(err){ + reject(err); + }else{ + try{ + o = body.match(o_params.reg)[1]; + resolve(o); + }catch(e){ + reject(e); + } + } + }); + }); +} + + +