全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
123
返回列表 发新帖
楼主: eqblog

利用Python3脚本监控enoctus是否有货

[复制链接]
发表于 2018-1-16 10:09:52 | 显示全部楼层
  1. #本脚本基于python3+方糖实现enoctus监控+微信推送
  2. #使用方法:
  3. #修改 sckey 为你自己的方糖KEY
  4. #修改 pid 为你想要监控的套餐PID
  5. #python vps.py
  6. #香港1G pid=93


  7. from sys import argv
  8. from urllib import request,parse
  9. from os import system
  10. import datetime
  11. sckey="xxxxxx"
  12. pid=93

  13. url='https://einstein.enoctus.co.uk/cart.php?a=add&pid=%s' % (pid)
  14. try:
  15.     flag=0
  16.     oktime=datetime.datetime.now()
  17.     oktime.strftime('%Y-%m-%d %H:%M:%S')
  18.     outoftime=datetime.datetime.now()
  19.     outoftime.strftime('%Y-%m-%d %H:%M:%S')
  20.     while True:
  21.         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'}
  22.         req=request.Request(url,headers=header)
  23.         page=request.urlopen(req).read()
  24.         if str(page).find('out of stock')>0:
  25.             if flag>0:
  26.                 outoftime=datetime.datetime.now()
  27.                 outoftime.strftime('%Y-%m-%d %H:%M:%S')
  28.                 timeout='本轮次上货持续时间:%s' % (outoftime-oktime)
  29.                 print(timeout)
  30.                 tile='%s%s' % ('缺货提醒',timeout)
  31.                 textmod={'text':tile,'desp':url}
  32.                 textmod = parse.urlencode(textmod)
  33.                 urlsc='https://sc.ftqq.com/%s.send' % (sckey)
  34.                 req1=request.Request(url='%s%s%s' % (urlsc,'?',textmod),headers=header)
  35.                 page1=request.urlopen(req1).read()
  36.             flag=0
  37.             print('缺货')
  38.         else:
  39.             if flag==0:
  40.                 oktime=datetime.datetime.now()
  41.                 oktime.strftime('%Y-%m-%d %H:%M:%S')
  42.                 timeok='本轮缺货持续时间:%s' % (oktime-outoftime)
  43.                 print(timeok)
  44.                 tile='%s%s' % ('上货提醒',timeok)
  45.                 textmod={'text':tile,'desp':url}
  46.                 textmod = parse.urlencode(textmod)
  47.                 urlsc='https://sc.ftqq.com/%s.send' % (sckey)
  48.                 req1=request.Request(url='%s%s%s' % (urlsc,'?',textmod),headers=header)
  49.                 page1=request.urlopen(req1).read()
  50.             flag=flag+1
  51.             print('有货')
  52.             if flag<3:
  53.                 tile='%s%s' % ('上货提醒',flag)
  54.                 textmod={'text':tile,'desp':url}
  55.                 textmod = parse.urlencode(textmod)
  56.                 urlsc='https://sc.ftqq.com/%s.send' % (sckey)
  57.                 req1=request.Request(url='%s%s%s' % (urlsc,'?',textmod),headers=header)
  58.                 page1=request.urlopen(req1).read()
  59. except:
  60.     print('脚本异常,退出')
复制代码
发表于 2018-1-16 10:51:11 | 显示全部楼层

File "q.py", line 1
SyntaxError: Non-ASCII character '\xe6' in file q.py on line 1, but no encoding declared; see
http://www.python.org/peps/pep-0263.html for details,

咋解决啊?大佬
发表于 2018-1-16 10:58:46 | 显示全部楼层
真不懂这东西有啥好的,MJJ们费劲了心思
 楼主| 发表于 2018-1-16 11:02:24 来自手机 | 显示全部楼层
十一 发表于 2018-1-16 10:51
File "q.py", line 1
SyntaxError: Non-ASCII character '\xe6' in file q.py on line 1, but no encodin ...

你应该用的Python2 请安装Python3
Python2里不让直接用中文
发表于 2018-1-16 11:06:46 | 显示全部楼层
eqblog 发表于 2018-1-16 11:02
你应该用的Python2 请安装Python3
Python2里不让直接用中文

感谢大佬,已解决,
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2025-9-19 09:31 , Processed in 0.081666 second(s), 8 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表