python ....

API_method^2
iotcat 4 years ago
parent bc57e025dd
commit 4b8b194d27
  1. 16
      index.js
  2. 6
      test.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(/<span(.*?)<\/span>/g)[0].match(/\d+(.\d+)?/g)[0];
console.log(erate);
callback(erate);
});}

@ -0,0 +1,6 @@
const request = require('request');
request('https://www.huilv.cc/GBP_CNY/', (err, header, body)=>{
var val = body.match(/<span(.*?)<\/span>/g)[0].match(/\d+(.\d+)?/g)[0];
console.log(val);
});
Loading…
Cancel
Save