mirror of https://github.com/IoTcat/coro-py.git
master
parent
676803fad1
commit
0b4bd72b3a
2 changed files with 43 additions and 0 deletions
@ -0,0 +1,5 @@ |
||||
const coro = require('./uk.js'); |
||||
|
||||
(async () => { |
||||
console.log(await coro()); |
||||
})() |
@ -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); |
||||
} |
||||
} |
||||
}); |
||||
}); |
||||
} |
||||
|
||||
|
||||
|
Loading…
Reference in new issue