以下来自 https://eqblog.com/whmcs-python-hon.html
http://www.hostloc.com/thread-422346-1-1.html
安装Python3 使用python3 x.py
#本脚本基于python3+方糖实现enoctus监控+微信推送
#使用方法:
#修改 sckey 为你自己的方糖KEY
#修改 pid 为你想要监控的套餐PID
#python vps.py
#香港1G pid=93
from sys import argv
from urllib import request,parse
from os import system
import datetime
sckey="xxxxxx"
pid=93
url='https://einstein.enoctus.co.uk/cart.php?a=add&pid=%s' % (pid)
try:
flag=0
oktime=datetime.datetime.now()
oktime.strftime('%Y-%m-%d %H:%M:%S')
outoftime=datetime.datetime.now()
outoftime.strftime('%Y-%m-%d %H:%M:%S')
while True:
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()
if str(page).find('out of stock')>0:
if flag>0:
outoftime=datetime.datetime.now()
outoftime.strftime('%Y-%m-%d %H:%M:%S')
timeout='本轮次上货持续时间:%s' % (outoftime-oktime)
print(timeout)
tile='%s%s' % ('缺货提醒',timeout)
textmod={'text':tile,'desp':url}
textmod = parse.urlencode(textmod)
urlsc='https://sc.ftqq.com/%s.send' % (sckey)
req1=request.Request(url='%s%s%s' % (urlsc,'?',textmod),headers=header)
page1=request.urlopen(req1).read()
flag=0
print('缺货')
else:
if flag==0:
oktime=datetime.datetime.now()
oktime.strftime('%Y-%m-%d %H:%M:%S')
timeok='本轮缺货持续时间:%s' % (oktime-outoftime)
print(timeok)
tile='%s%s' % ('上货提醒',timeok)
textmod={'text':tile,'desp':url}
textmod = parse.urlencode(textmod)
urlsc='https://sc.ftqq.com/%s.send' % (sckey)
req1=request.Request(url='%s%s%s' % (urlsc,'?',textmod),headers=header)
page1=request.urlopen(req1).read()
flag=flag+1
print('有货')
if flag<3:
tile='%s%s' % ('上货提醒',flag)
textmod={'text':tile,'desp':url}
textmod = parse.urlencode(textmod)
urlsc='https://sc.ftqq.com/%s.send' % (sckey)
req1=request.Request(url='%s%s%s' % (urlsc,'?',textmod),headers=header)
page1=request.urlopen(req1).read()
except:
print('脚本异常,退出')