#!/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)