master
iotcat 4 years ago
parent 4f760b3a6f
commit 26ed34948f
  1. 1
      .gitignore
  2. 65
      index.js
  3. 4
      node_modules/ushio-sms/README.md
  4. 12
      node_modules/ushio-sms/index.js
  5. 30
      node_modules/ushio-sms/package.json
  6. 4
      node_modules/ushio-sms/test.js
  7. 14
      package-lock.json
  8. 3
      package.json
  9. 3
      test.js

1
.gitignore vendored

@ -1 +1,2 @@
node_modules/
var/

@ -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:''} <strong>已确诊${info.confirmedCount}人, 疑似${info.suspectedCount}, 治愈${info.curedCount}, 死亡${info.deadCount}</strong>。
\n\r<br><br>
以上数据自动抓取自丁香医生
\n\r<br><br>
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;
}

4
node_modules/ushio-sms/README.md generated vendored

@ -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
Apache-2.0

12
node_modules/ushio-sms/index.js generated vendored

@ -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;

@ -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"
}

4
node_modules/ushio-sms/test.js generated vendored

@ -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'));
})();
})();

14
package-lock.json generated

@ -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"
}

@ -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"
}
}

@ -4,4 +4,5 @@ var uk = coro({
province: '山东省',
city: '泰安',
debug: true
});
});

Loading…
Cancel
Save