-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_return_ticket.py
150 lines (122 loc) · 4.86 KB
/
check_return_ticket.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import requests,json,urllib3
import datetime,time
from loguru import logger
detail_id="85939"
web_url = "https://oapi.dingtalk.com/robot/send?access_token=" #填写钉钉推送token
bl = "https://api.day.app/" #填写bark推送token
token = '' #在pushpush网站中可以找到,填写pushpush推送token
logger.add("loguru.log")
def ding_push_message():
# 构建请求头部
header = {
"Content-Type": "application/json",
"Charset": "UTF-8"
}
# 构建请求数据
message = {
"msgtype": "text",
"text": {
"content": msg
},
"at": {
"isAtAll": True
}
}
# 对请求的数据进行json封装
message_json = json.dumps(message)
# 发送请求
info = requests.post(url=web_url, data=message_json, headers=header)
# 打印返回的结果
logger.info(info.text)
def pushplus_notify(title,content):
today=datetime.date.today()
date_text=today.strftime("%Y-%m-%d")
title= title+date_text
url = 'http://www.pushplus.plus/send'
data = {
"token":token,
"title":title,
"content":content
}
body=json.dumps(data).encode(encoding='utf-8')
headers = {'Content-Type':'application/json'}
requests.post(url,data=body,headers=headers)
def send2bark(self,title, content):
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
try:
for i in range(1):
msg = "{0}/{1}/{2}/?sound=update".format(bl, title, content)
link = msg
res = requests.get(link, verify=False)
except Exception as e:
logger.error('Reason:', e)
return
return
if __name__=='__main__':
while True:
try:
with open("settings.json",'r',encoding='utf-8')as settings_f:
settings=json.load(settings_f)
except:
settings={}
settings['id']=detail_id
with open("settings.json",'w',encoding='utf-8')as settings_f:
json.dump(settings, settings_f,ensure_ascii=False)
headers = {
'authority': 'show.bilibili.com',
'accept': '*/*',
'accept-language': 'zh-CN,zh;q=0.9',
'cookie': '',
'referer': 'https://show.bilibili.com/platform/detail.html?id='+detail_id,
'sec-ch-ua': '"Not_A Brand";v="99", "Google Chrome";v="109", "Chromium";v="109"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-origin',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
}
url='https://show.bilibili.com/api/ticket/project/getV2?version=134&id='+detail_id+'&project_id='+detail_id+'&requestSource=pc-new'
try:
response = requests.get(url=url, headers=headers)
response=response.json()
title=response['data']['name']
for screen in response['data']['screen_list']:
name=screen['name']
if(screen['saleFlag']['number']==2):
msg=name+' 有余票了!\n正在检测有余票项目'
logger.info(msg)
try:
ding_push_message()
except Exception as e:
logger.error('\n钉钉推送出错!\n')
try:
pushplus_notify('监控'+name+'有余票!',msg)
except Exception as e:
logger.error('\nPushPlus推送出错!\n')
try:
send2bark(1,'监控'+name+'有余票!',msg)
except Exception as e:
logger.error('\nbark推送出错!\n')
for ticket in screen['ticket_list']:
if(ticket['sale_flag']['number']==2):
screen_name=ticket['screen_name']
desc=ticket['desc']
msg=screen_name+desc+' 有余票了!\n'
logger.info(msg)
try:
ding_push_message()
except Exception as e:
logger.error('\n钉钉推送出错!\n')
try:
pushplus_notify('监控'+title+'有余票!',msg)
except Exception as e:
logger.error('\nPushPlus推送出错!\n')
try:
send2bark(1,'监控'+title+'有余票!',msg)
except Exception as e:
logger.error('\nbark推送出错!\n')
except Exception as e:
logger.debug(response.text)
logger.error('\n本轮请求出错!\n')
time.sleep(5)