feat: covid疫苗余量查询

This commit is contained in:
lyz05
2022-12-13 21:10:47 +08:00
parent 35de84a7c3
commit 0cb3e82f08
4 changed files with 43 additions and 11 deletions

2
app.js
View File

@@ -56,7 +56,7 @@ schedule(app);
if (!DEBUG) {
console.log("PRODUCTION MODE!该模式下TG机器人正常运行");
// 引入TG机器人
require("./tgbot/bot");
require("./tgbot/tgbot");
} else
console.log("DEBUG MODE!该模式下将关闭TG机器人");

27
schedule/covidbook.js Normal file
View File

@@ -0,0 +1,27 @@
const axios = require('axios');
const tgbot = require("../tgbot/tgbot.js");
const rootPath = 'https://eservice.ssm.gov.mo/covidvacbook/'
const url = rootPath + 'Booking/GetLocationQuotaList';
if (!module.parent) {
// 引入环境变量
require("dotenv").config('../.env');
}
console.log('covidbook.js loaded')
function main() {
axios.post(url).then((res) => {
const data = res.data;
const mrnalocationquotalist = data.filter(locationquota => (locationquota.rspsrv === 'HC6' || locationquota.rspsrv === 'HC8' || locationquota.rspsrv === 'CHCSJ(MRNA)' || locationquota.rspsrv === 'CHCSJ2(MRNA)' || locationquota.rspsrv === 'SSM1(MRNA)'));
const ret = mrnalocationquotalist.filter(x => x.sum != '0')
if (ret.length != 0) {
console.log('有余量');
const bot = tgbot.hkaliyun;
bot.sendMessage(619935997, "有余量!");
bot.sendMessage(619935997, JSON.stringify(ret));
} else console.log('无余量');
})
}
module.exports = main;

View File

@@ -3,6 +3,7 @@ const leancloud = require("../utils/leancloud");
const chai = require("chai");
const chaiHttp = require("chai-http");
const cf2dns = require("./cf2dns");
const covidbook = require("./covidbook");
function subcache(app) {
console.log("Running Cron Jobsubcache");
@@ -31,9 +32,10 @@ module.exports = (app) => {
result
});
});
covidbook();
});
};
if (!module.parent) {
cf2dns();
covidbook();
}

View File

@@ -1,20 +1,23 @@
require("dotenv").config({path: "../.env"});
const memory = require("../utils/memory");
const hkaliyun = require("./bot/hkaliyun.js");
const airportsub = require("./bot/airportsub.js");
const bots = [
hkaliyun(process.env.TELEGRAM_TOKEN_HKALIYUN),
airportsub(process.env.TELEGRAM_TOKEN_AIRPORTSUB),
];
const bots = {
hkaliyun: hkaliyun(process.env.TELEGRAM_TOKEN_HKALIYUN),
airportsub: airportsub(process.env.TELEGRAM_TOKEN_AIRPORTSUB),
};
console.log("bot.js loaded");
memory();
for (const bot of bots) {
bot.getMe().then((botInfo) => {
for (const bot in bots) {
bots[bot].getMe().then((botInfo) => {
console.log("Bot info:", botInfo);
});
bot.deleteWebHook();
bots[bot].deleteWebHook();
// bot.getWebHookInfo().then((webhookInfo) => {
// console.log('Webhook info:', webhookInfo);
// });
}
module.exports = bots;