diff --git a/.gitignore b/.gitignore index 002f89c..8077df2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules/ +var/ diff --git a/index.js b/index.js index 6d4c14a..caf74d9 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,8 @@ var get = (o_params)=>{ var o = { province: null, city: null, - tel: ['18118155257'], + sms: ['18118155257'], + mail: ['i@yimian.xyz'], success: ()=>{}, error: ()=>{}, url: 'https://lab.isaaclin.cn/nCoV/api/area', @@ -13,7 +14,22 @@ var get = (o_params)=>{ Object.assign(o, o_params); const request = require('request'); - const sms = require('ushio-sms').sms('https://api.yimian.xyz/sms/'); + const os = require('os'); + const fs = require('fs'); + const sms = require('ushio-sms')('https://api.yimian.xyz/sms/'); + const mail = require('ushio-mail')('https://api.yimian.xyz/mail/'); + + const fileBck = /*os.tmpdir() + ((os.platform() == 'win32')?'\\':'/') + */__dirname + `/var/${o.province+o.city}.tmp`; + var updateTime = 0; + fs.access(fileBck ,function(err){ + if(err && err.code == "ENOENT"){ + updateTime = 0; + }else{ + updateTime = fs.readFileSync(fileBck, 'utf8'); + } + unit(); + }) + const getInfo = ()=>{ return new Promise((resolve, reject) => request(o.url + ((o.province)?`?province=${encodeURI(o.province)}`:``), (err, res, body) => { @@ -36,14 +52,55 @@ var get = (o_params)=>{ const unit = async () => { var info = await getInfo(); - console.log(info) + console.log(info); + + if(info.updateTime == updateTime){ + updateTime = info.updateTime; + fs.writeFileSync(fileBck, updateTime); + await push(info); + } if(!o.debug){ setTimeout(unit, o.interval); } } - unit(); + + const push = info => new Promise(async resolve => { + await pushMail(info); + setTimeout(pushSms, o.interval/2, info); + }); + + + const pushMail = info => new Promise(async resolve => { + for(var index = 0; index < o.mail.length; index++){ + await mail.send( + o.mail[index], + `冠状病毒 ${o.province} ${(o.city)?o.city:''} 确诊 ${info.confirmedCount}`, + `截至${new Date(updateTime)}, ${o.province} ${(o.city)?o.city:''} 已确诊${info.confirmedCount}人, 疑似${info.suspectedCount}, 治愈${info.curedCount}, 死亡${info.deadCount}。 + +\n\r

+ +以上数据自动抓取自丁香医生。 +\n\r

+ +iotcat(https://iotcat.me)`, + 'iotcat-py' + ); + } + resolve(); + }); + + const pushSms = info => new Promise(async resolve => { + for(var index = 0; index < o.sms.length; index++){ + await sms.send( + o.sms[index], + `${o.province}${(o.city)?o.city:''}确诊${info.confirmedCount}`, + '提醒您' + ); + } + resolve(); + }); return o; } diff --git a/node_modules/ushio-sms/README.md b/node_modules/ushio-sms/README.md index f4171be..c9142b1 100644 --- a/node_modules/ushio-sms/README.md +++ b/node_modules/ushio-sms/README.md @@ -5,7 +5,7 @@ ### Import sms module ```js -const sms = require('ushio-sms').sms(API_url); //substitute the API_url +const sms = require('ushio-sms')(API_url); //substitute the API_url ``` @@ -17,4 +17,4 @@ await sms.send(Tel, Msg0, Msg1); ## License -Apache-2.0 \ No newline at end of file +Apache-2.0 diff --git a/node_modules/ushio-sms/index.js b/node_modules/ushio-sms/index.js index 5b3bf91..4d6f730 100644 --- a/node_modules/ushio-sms/index.js +++ b/node_modules/ushio-sms/index.js @@ -11,7 +11,15 @@ var sms = (url) => { var send = (to, msg0, msg1) => { return new Promise((resolve, reject) => { - request(url + `?to=${to}&s0=${msg0}&s1=${msg1}&t=${Date.parse(new Date())/1000}`, (err, res, body) => { + request.post({ + "url": url, + formData: { + "to": to, + "s0": msg0, + "s1": msg1, + "t": Date.parse(new Date())/1000 + } + }, (err, res, body) => { resolve(body); }); }); @@ -21,5 +29,5 @@ var sms = (url) => { } -exports.sms = sms; +module.exports = sms; diff --git a/node_modules/ushio-sms/package.json b/node_modules/ushio-sms/package.json index 056e262..fff88d4 100644 --- a/node_modules/ushio-sms/package.json +++ b/node_modules/ushio-sms/package.json @@ -1,31 +1,27 @@ { - "_args": [ - [ - "ushio-sms@1.0.0", - "e:\\git\\coron-lstn" - ] - ], - "_from": "ushio-sms@1.0.0", - "_id": "ushio-sms@1.0.0", + "_from": "ushio-sms@^1.0.2", + "_id": "ushio-sms@1.0.3", "_inBundle": false, - "_integrity": "sha512-gVJnsJ+vpOghc1gwjEgx/wTIUSYAZrrEI56oR3i7CgrLkC7PoLf/kECrriIahGf0dL9pXLhVHx2AP3q2N72FXg==", + "_integrity": "sha512-EQl+XWhimBPuJ1q863VSxivpJC589sXH3xPfeeZQHV3VwXdUfG3ETNOCjGWy3/LgQxk2INnYV4cItlYSfVRpug==", "_location": "/ushio-sms", "_phantomChildren": {}, "_requested": { - "type": "version", + "type": "range", "registry": true, - "raw": "ushio-sms@1.0.0", + "raw": "ushio-sms@^1.0.2", "name": "ushio-sms", "escapedName": "ushio-sms", - "rawSpec": "1.0.0", + "rawSpec": "^1.0.2", "saveSpec": null, - "fetchSpec": "1.0.0" + "fetchSpec": "^1.0.2" }, "_requiredBy": [ + "#USER", "/" ], - "_resolved": "https://registry.npmjs.org/ushio-sms/-/ushio-sms-1.0.0.tgz", - "_spec": "1.0.0", + "_resolved": "https://registry.npmjs.org/ushio-sms/-/ushio-sms-1.0.3.tgz", + "_shasum": "03c60579d2abb9b5fca869eb376bbe3f3bb7f48e", + "_spec": "ushio-sms@^1.0.2", "_where": "e:\\git\\coron-lstn", "author": { "name": "iotcat" @@ -33,9 +29,11 @@ "bugs": { "url": "https://github.com/iotcat/ushio-sms/issues" }, + "bundleDependencies": false, "dependencies": { "request": "^2.88.0" }, + "deprecated": false, "description": "sms for ushio", "homepage": "https://github.com/iotcat/ushio-sms#readme", "keywords": [ @@ -52,5 +50,5 @@ "scripts": { "test": "test.js" }, - "version": "1.0.0" + "version": "1.0.3" } diff --git a/node_modules/ushio-sms/test.js b/node_modules/ushio-sms/test.js index 8c24969..626389a 100644 --- a/node_modules/ushio-sms/test.js +++ b/node_modules/ushio-sms/test.js @@ -1,5 +1,5 @@ -const sms = require('./index.js').sms('https://api.yimian.xyz/sms/'); +const sms = require('./index.js')('https://api.yimian.xyz/sms/'); (async () => { console.log(await sms.send('18118155257', 'test', 'send')); -})(); \ No newline at end of file +})(); diff --git a/package-lock.json b/package-lock.json index 50355dc..dc43074 100644 --- a/package-lock.json +++ b/package-lock.json @@ -327,10 +327,18 @@ "punycode": "^2.1.0" } }, + "ushio-mail": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/ushio-mail/-/ushio-mail-1.0.3.tgz", + "integrity": "sha512-140iGlk9LrxuYkNBF8qpUOGoxyVIm7Ad+f7Vqg3jNbJUkkPCq+llFwl/uxqo97xYhgQdOft4VmckxXD7eCUG0g==", + "requires": { + "request": "^2.88.0" + } + }, "ushio-sms": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/ushio-sms/-/ushio-sms-1.0.0.tgz", - "integrity": "sha512-gVJnsJ+vpOghc1gwjEgx/wTIUSYAZrrEI56oR3i7CgrLkC7PoLf/kECrriIahGf0dL9pXLhVHx2AP3q2N72FXg==", + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/ushio-sms/-/ushio-sms-1.0.3.tgz", + "integrity": "sha512-EQl+XWhimBPuJ1q863VSxivpJC589sXH3xPfeeZQHV3VwXdUfG3ETNOCjGWy3/LgQxk2INnYV4cItlYSfVRpug==", "requires": { "request": "^2.88.0" } diff --git a/package.json b/package.json index c62d11f..70d11dd 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "homepage": "https://github.com/iotcat/coron-lstn#readme", "dependencies": { "request": "^2.88.0", - "ushio-sms": "^1.0.0" + "ushio-mail": "^1.0.3", + "ushio-sms": "^1.0.3" } } diff --git a/test.js b/test.js index cac2860..a4d583f 100644 --- a/test.js +++ b/test.js @@ -4,4 +4,5 @@ var uk = coro({ province: '山东省', city: '泰安', debug: true -}); \ No newline at end of file +}); +