forked from evelister/Bilibili-Automatic-lottery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (57 loc) · 2.33 KB
/
main.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
import requests
import re
import time
class Bili():
def __init__(self):
self.sendurl = 'http://api.vc.bilibili.com/dynamic_repost/v1/dynamic_repost/repost'
self.followurl = 'http://api.bilibili.com/x/relation/modify'
self.uid = 这里是uid
self.crsf = 这里是crsf_token
self.cookie = {'Cookie': '这里是cookie'}
self.header = {'User-Agent': '这里是user-agent'}
def get(self):
res = requests.get(geturl1, cookies=self.cookie, headers=self.header)
cards = res.json().get('data').get('cards')
for card in cards:
card1 = card.get('card')
pattern = re.compile('"orig_dy_id": (.*?), "pre_dy_id.*?uid": (.*?), "uname', re.S)
items = re.findall(pattern, card1)
for item in items:
yield {
'dynamic_id': item[0],
'uid': item[1]
}
def follow(self):
data = {
'fid': item['uid'],
'act': 1,
're_src': 11,
'jsonp': 'jsonp',
'csrf': self.crsf
}
requests.post(self.followurl, data=data, cookies=self.cookie, headers=self.header)
def send(self):
data = {
'uid': self.uid,
'dynamic_id': item['dynamic_id'],
'content': '//@飞碟说 @天天卡牌 @某幻君 :转发动态',
'at_uids': '5581898,10462362,1577804',
'ctrl': '[{"data":"5581898","location":2,"length":4,"type":1},{"data":"10462362","location":7,"length":5,"type":1},{"data":"1577804","location":13,"length":4,"type":1}]',
'csrf_token': self.crsf
}
requests.post(self.sendurl, data=data, cookies=self.cookie, headers=self.header)
if __name__ == "__main__":
host_uids = [387594603, 23131813, 123469889, 397155220]#这是四个抽奖up,可以修改
geturl = 'http://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history?host_uid=%s&offset_dynamic_id=0'
bili = Bili()
for host_uid in host_uids:
i = 0
geturl1 = geturl % (host_uid)
for item in bili.get():
bili.follow()
bili.send()
i = i + 1
if i % 10 == 0:
time.sleep(120)
time.sleep(120)
print(i)