运行一个自动监控报警脚本

192 阅读1分钟

最近有些消息我天天盯着看,眼睛都看瞎了,写了一个自动报警器,有一场就会播放一个提示音

使用nodejs监控,然后读取本地音频,触发条件就播放提示音

监控端截图

image.png

打码后的源代码

const path = require("path");
const sound = require('sound-play')
const axios = require('axios');

const alertme = async () => {
	try {
		const filePath = path.join(__dirname, "11.mp3");
		await sound.play(filePath);
		console.log("done");
	} catch (error) {
                console.error(error);
	}
}

let i = 0
const loop = async () => {
	i++
	try {
		const res = await axios.get("你的监控地址")
		const data = res.data
		const floorPrice = data.floorPrice / 1e8
		console.log("price: " + floorPrice + '           time: ' + new Date().toLocaleString())
		
		if(floorPrice <= 0.074){
			await alertme()
		}
		setTimeout(() => {
			loop()
		}, 10e3)	
	} catch (error) {
	  console.error(error);
	}
}
loop()

就这样,DYOR

--完--