#本脚本调用了sendmail,所以得先确保你的sendmail可用
#注意本脚本只适用于python3,centos安装python3教程请看:https://eqblog.com/centos-install-python3-6-4.html

CentOS下安装sendmail方法:

yum install sendmail -y
service sendmail start

#注意:确保网络25端口已经开启

脚本直链下载:https://eqblog.com/script/i.py

接下来将以下脚本存为一个文件,本文以1.py做示例:

vi 1.py
#然后将以下的code复制进你的文件
:wq

使用格式:

python3 1.py pid email

pid为产品的pid
email为你的邮箱
示例:

python3 1.py 93 [email protected]

code:
#将以下url中的网址换为其它whmcs即可实现监控其它网址

from sys import argv
from urllib import request
from os import system
try:
 flag=0
 while True:
    url='https://einstein.enoctus.co.uk/cart.php?a=add&pid='+argv[1]
    header={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36'}
    req=request.Request(url,headers=header)
    page=request.urlopen(req).read()
    with open('content.txt','w') as f:
        f.write('有货了,链接是:'+url)
    if str(page).find('out of stock')>0:
        flag=0
        print('无货')
    else:
        flag=flag+1
        print('有货')
        if flag<3:
            system("mail -s '有货了' {0} < content.txt".format(argv[2]))

except:
    print('脚本异常,退出')