获取大麦网孟鹤堂演出数据并播报和在右下角弹窗提示
#!/usr/bin/env python
# coding=utf-8#!/usr/bin/env python
# coding=utf-8
# 获取大麦网孟鹤堂演出数据并播报和在右下角弹窗提示
import requests
import win32com.client
from lxml import etree
import json,time
from show_msg import TestTaskbarIcon
class Check():
def __init__(self):
self.speaker = win32com.client.Dispatch("SAPI.SpVOice")
self.headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36"}
self.damai_url = 'https://detail.damai.cn/item.htm?spm=' \
'a2oeg.search_category.0.0.a7036164RquLgS&id=592881382534&clicktitle=' \
'%E5%AD%9F%E9%B9%A4%E5%A0%82%E7%9B%B8%E5%A3%B0%E4%B8%93%E5%9C%BA-%E5%A4%A9%E6%B4%A5%E7%AB%99'
# 处理check
def check(self,t):
while True:
print("-")
time.sleep(2)
response = requests.get(self.damai_url,headers=self.headers)
html = etree.HTML(response.text)
result = html.xpath('//div[@id="dataDefault"]/text()')[0]
# with open("meng.html",'w',encoding='utf-8')as f:
# f.write(response.text)
dic_json = json.loads(result)
# print((dic_json['performBases'][0]['performs'][0]['skuList'][1]['priceId']))
dic = dic_json['performBases'][0]['performs'][0]['skuList']
for i in range(0,4):
sku = (dic[i])
if sku['priceId'] == 220767038:
if len(sku['promotionTags']) == 0:
t.showMsg("280有货啦", "280")
print("280有货啦")
self.speaker.Speak('280有货啦') # 播报名字
else:
self.speaker.Speak('280无货') # 播报名字
elif sku['priceId'] == 220775022:
if len(sku['promotionTags']) == 0:
t.showMsg("680有货啦", "680")
print("680有货啦")
self.speaker.Speak('680有货啦') # 播报名字
else:
self.speaker.Speak('680无货') # 播报名字
elif sku['priceId'] == 220765017:
if len(sku['promotionTags']) == 0:
t.showMsg("880有货啦", "880")
print("880有货啦")
self.speaker.Speak('880有货啦') # 播报名字
else:
self.speaker.Speak('880无货') # 播报名字
else:
if len(sku['promotionTags']) == 0:
t.showMsg("480有货啦", "480")
print("480有货啦")
self.speaker.Speak('480有货啦') # 播报名字
else:
self.speaker.Speak('480无货') # 播报名字
if __name__ == "__main__":
t = TestTaskbarIcon()
ch = Check()
ch.check(t)
弹窗模块show_msg.py:
#!/usr/bin/env python
# coding=utf-8
# 在右下角进行弹窗提示
import win32gui
import win32con
import time
class TestTaskbarIcon:
def __init__(self):
# 注册一个窗口类
wc = win32gui.WNDCLASS()
hinst = wc.hInstance = win32gui.GetModuleHandle(None)
wc.lpszClassName = "PythonTaskbarDemo"
wc.lpfnWndProc = {win32con.WM_DESTROY: self.OnDestroy, }
classAtom = win32gui.RegisterClass(wc)
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
self.hwnd = win32gui.CreateWindow(classAtom, "Taskbar Demo", style,
0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT,
0, 0, hinst, None)
hicon = win32gui.LoadIcon(0, win32con.IDI_APPLICATION)
nid = (self.hwnd, 0, win32gui.NIF_ICON, win32con.WM_USER + 20, hicon, "Demo")
win32gui.Shell_NotifyIcon(win32gui.NIM_ADD, nid)
def showMsg(self, title, msg):
nid = (self.hwnd, # 句柄
0, # 托盘图标ID
win32gui.NIF_INFO, # 标识
0, # 回调消息ID
0, # 托盘图标句柄
"TestMessage", # 图标字符串
msg, # 气球提示字符串
0, # 提示的显示时间
title, # 提示标题
win32gui.NIIF_INFO # 提示用到的图标
)
win32gui.Shell_NotifyIcon(win32gui.NIM_MODIFY, nid)
def OnDestroy(self, hwnd, msg, wparam, lparam):
nid = (self.hwnd, 0)
win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, nid)
win32gui.PostQuitMessage(0) # Terminate the app.
if __name__ == '__main__':
t = TestTaskbarIcon()
t.showMsg("您有新的文件,请登录查看", "Mr a2man!")
# time.sleep(5)
# win32gui.DestroyWindow(t.hwnd)