9

Python3版Kimsufi监控脚本,带电报推送功能

 3 years ago
source link: https://vps.la/2022/01/04/python3%e7%89%88kimsufi%e7%9b%91%e6%8e%a7%e8%84%9a%e6%9c%ac%ef%bc%8c%e5%b8%a6%e7%94%b5%e6%8a%a5%e6%8e%a8%e9%80%81%e5%8a%9f%e8%83%bd/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Python3版Kimsufi监控脚本,带电报推送功能 - VPS啦-VPS啦

Github地址:https://github.com/uselibrary/monitor_for_kimsufi
博客地址:https://pa.ci/165.html

此前PHP版本的Kimsufi上货监控由于OVH更改了程序逻辑,已经彻底失效了。所以重新使用Python3写了一个Kimsufi上货监控。提醒方式由之前的server酱发微信消息换成了电报/telegram机器人推送通知,因为新版的server酱每天只有5条免费的推送额度,无法满足监控的多推送要求。

支持的系统:CentOS 7+, Ubuntu 18.04+, Debian 9+等
软件和环境:Python3、pip
如果没有安装pip,可使用以下命令进行安装:

yum install python3-pip -y #适用于CentOS
apt install python3-pip -y #适用于Ubuntu和Debian

安装Python脚本,使用crontab定时运行

在/home文件夹中(也可以是其他路径),执行以下命令。
首先,命令安装脚本的依赖包:

pip install jsonpath
pip install requests其次,下载脚本并修改参数:

wget –no-check-certificate -O kimsufi.py https://raw.githubusercontent.com/uselibrary/monitor_for_kimsufi/master/kimsufi.py && chmod +x kimsufi.py

使用vim、nano或者任何你常用的编辑器打开kimsufi.py,配置以下内容:

country_code = ‘eu’
hardware_code = ‘2201sk040’
chat_id_code = ‘521704743’
token_code = ‘170491216:SFR-F456_Rcm4-WwBHBdicBHailBgB’

其中,country_code 后面的是账号的所在地,比如欧区的是eu,美区的是us;hardware_code是机器的代号,比如欧区的KS-1的代号是2201sk010(区域和对应的机器代号要匹配,具体代码可以查看网页源代码);chat_id_code是telegram机器人的chat id;token_code是telegram机器人的token。不会电报机器人或者没有申请机器人的,请参考这里:https://pa.ci/119.html 跟随申请telegram bot部分进行操作即可。

最后,使用crontab定时运行脚本:
在终端中输入crontab -e,在其中输入以下内容(注意kimsufi.py的路径):

*/1 * * * * /usr/bin/python3 /home/kimsufi.py

至此,就完成了Kimsufi的监控,每分钟检查一次是否有货,一旦发现有货,就会在电报/telegram上推送消息,并给出具体是哪个机房有货。

未经允许不得转载:VPS啦 » Python3版Kimsufi监控脚本,带电报推送功能


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK