From 4b8b194d27f70d4152abde9e8362de2e11f8f483 Mon Sep 17 00:00:00 2001 From: iotcat Date: Tue, 7 Jan 2020 16:13:56 +0000 Subject: [PATCH] python .... --- index.js | 16 +++++++--------- test.js | 6 ++++++ 2 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 test.js diff --git a/index.js b/index.js index 6d0eefd..0d50000 100644 --- a/index.js +++ b/index.js @@ -5,16 +5,16 @@ var ref = 9.4; var LastRefDate = new Date(); const thre = 0.2; const maxDays = 5; -const checkInterval = 1000*60*5; +const checkInterval = 1000//*60*5; setInterval(()=>{ getRate("GBP", "CNY", (rate)=>{ console.log((new Date()) + " - GBP->CNY :: " + rate + " ref: " + ref); if(rate < ref - thre){ console.log("GBP DOWN!!"); - mail("i@yimian.xyz", `GBP DOWN TO ${rate}`, `Current Rate: ${rate}, Ref Rate: ${ref}`); - sms("18118155257", `英镑跌至${rate}`, `发消息提醒`); - sms("15827586269", `英镑跌至${rate}`, `发消息提醒`); + //mail("i@yimian.xyz", `GBP DOWN TO ${rate}`, `Current Rate: ${rate}, Ref Rate: ${ref}`); + //sms("18118155257", `英镑跌至${rate}`, `发消息提醒`); + //sms("15827586269", `英镑跌至${rate}`, `发消息提醒`); ref = rate; LastRefDate = new Date(); } @@ -28,12 +28,10 @@ setInterval(()=>{ var getRate = (from = "GBP", to = "CNY", callback) => { -request(`https://webapi.huilv.cc/api/exchange?num=100&chiyouhuobi=${from}&duihuanhuobi=${to}`, function (error, response, body) { +request(`https://www.huilv.cc/${from}_${to}/`, function (error, response, body) { if (error) console.log('error:', error); // Print the error if one occurred - var jisuanjieguo = (res) => { - return res.dangqianhuilv; - }; - var erate = eval(body); + var erate = body.match(//g)[0].match(/\d+(.\d+)?/g)[0]; + console.log(erate); callback(erate); });} diff --git a/test.js b/test.js new file mode 100644 index 0000000..4ccc291 --- /dev/null +++ b/test.js @@ -0,0 +1,6 @@ +const request = require('request'); + +request('https://www.huilv.cc/GBP_CNY/', (err, header, body)=>{ + var val = body.match(//g)[0].match(/\d+(.\d+)?/g)[0]; + console.log(val); +});