-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathb_comment.py
executable file
·151 lines (133 loc) · 4.39 KB
/
b_comment.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
151
# -*- coding: utf-8 -*-
'''
B站评论监控
@File : test2.py
@Time : 2020/07/11
@Author : 未闻丶死讯
@Contact : [email protected]
'''
import requests
import re
import time
import os
import random
have = []
os.system('bash Blog.sh')
# 你的b站cookies 不知道怎么获取自己百度
f = open("cook")
cooke = f.read()
f.close()
sid = re.findall('sid\t(.*)\n', cooke)[0]
uid = re.findall("DedeUserID\t(.*)\n", cooke)[0]
DedeUserID__ckMd5 = re.findall("DedeUserID__ckMd5\t(.*?)\n", cooke)[0]
SESSDATA = re.findall("SESSDATA\t(.*?)\n", cooke)[0]
csrf = re.findall("bili_jct\t(.*?)$", cooke)[0]
cook = f"sid={sid}; DedeUserID={uid}; DedeUserID__ckMd5={DedeUserID__ckMd5}; SESSDATA={SESSDATA}; bili_jct={csrf};"
print(cook)
f = open("msg_dist.json")
msg_dist = f.read()
f.close()
msg_dist = eval(msg_dist)
def BV_AV(BV):
table = 'fZodR9XQDSUm21yCkr6zBqiveYah8bt4xsWpHnJE7jL5VG3guMTKNPAwcF'
tr = {}
for i in range(58):
tr[table[i]] = i
s = [11, 10, 3, 8, 4, 6]
xor = 177451812
add = 8728348608
r = 0
for i in range(6):
r += tr[BV[s[i]]] * 58 ** i
return (r - add) ^ xor
def _Send(BV, msg):
url = "https://api.bilibili.com/x/v2/reply/add"
aid = BV_AV(BV)
data = {
'oid': f'{aid}',
'type': '1',
'message': f'{msg}',
'plat': '1',
'jsonp': 'jsonp',
'csrf': f'{csrf}',
}
headers = {
'accept': 'application/json, text/javascript, */*; q=0.01',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8',
'content-length': '114',
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
'cookie': f"{cook}",
'origin': 'https://www.bilibili.com',
'referer': f'https://www.bilibili.com/video/{BV}',
'sec-fetch-dest': 'empty',
'sec-fetch-mode': 'cors',
'sec-fetch-site': 'same-site',
'user-agent': "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
}
session = requests.Session()
if session.post(url=url, data=data, headers=headers).status_code == 200:
_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(_time + "--" + BV + "已评论")
else:
_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(_time + "--" + BV + "false!!")
def get_BV_list():
headers = {
'cookie': f"{cook}",
'user-agent': "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36"
}
a = requests.get(
url=f"https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new?uid={uid}&type_list=8",
headers=headers).json()
# return re.findall('"bvid":"(.*?)"', a)[:5]
try:
a = a['data']['cards'][:5]
except:
a=[]
return a
def save_have():
global have
if have:
with open("hava.txt", "w+") as f:
for x in have:
f.write(str(x) + "\n")
if os.path.exists("hava.txt"):
with open("hava.txt", "r") as f:
have = f.read().split("\n")[:-1]
def main():
global have
global msg_dist
i = 0
while True:
i += 1
BV_list = get_BV_list()
for x in BV_list:
buid = str(x['desc']['uid'])
bvid = str(x['desc']['bvid'])
if bvid not in have:
if buid in msg_dist:
# print(2)
print(msg_dist[buid],end='--->>')
_Send(bvid, msg_dist[buid])
else:
_Send(bvid, "前来支持,[doge]")
have.append(bvid)
if i == 10:
i = 0
save_have()
time.sleep(random.randint(5, 7))
if __name__ == '__main__':
save_have()
main()
# _message="""
# 三连进度▓░░░░░░░░░10%……
# 三连进度▓▓▓░░░░░░░30%……
# 三连进度▓▓▓▓▓░░░░░50%……
# 三连进度▓▓▓▓▓▓▓░░░70%……
# 三连进度▓▓▓▓▓▓▓▓▓░90%……
# 三连进度▓▓▓▓▓▓▓▓▓▓99%……
# 三连失败[doge]
# 下次一定[doge]
# """
# _Send("BV1ra4y1h77c", _message)