Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Commit

Permalink
架构更新 逻辑调整
Browse files Browse the repository at this point in the history
  • Loading branch information
nico committed Apr 3, 2018
1 parent ef47247 commit a818e71
Show file tree
Hide file tree
Showing 14 changed files with 940 additions and 795 deletions.
201 changes: 0 additions & 201 deletions API.py

This file was deleted.

66 changes: 22 additions & 44 deletions LotteryResult.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,29 @@


class LotteryResult():

def __init__(self, bilibili):
self.bilibili =bilibili

async def query(self):

while 1:
if self.bilibili.activity_raffleid_list:
for i in range(0,len(self.bilibili.activity_roomid_list)):
url = "http://api.live.bilibili.com/activity/v1/Raffle/notice?roomid="+str(self.bilibili.activity_roomid_list[0])+"&raffleId="+str(self.bilibili.activity_raffleid_list[0])
headers = {
'Accept': 'application/json, text/plain, */*',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36',
'Accept-Language': 'zh-CN,zh;q=0.9',
'accept-encoding': 'gzip, deflate',
'Host': 'api.live.bilibili.com',
'cookie': self.bilibili.cookie,
}
response = requests.get(url, headers=headers)
try:
print("# 房间", str(self.bilibili.activity_roomid_list[0]).center(9), "网页端活动抽奖结果:", response.json()['data']['gift_name']+"x"+str(response.json()['data']['gift_num']))
del self.bilibili.activity_roomid_list[0]
del self.bilibili.activity_raffleid_list[0]
del self.bilibili.activity_time_list[0]
except:
pass
# print('lotteryresult test')
bilibili().clean_activity()

# print(self.bilibili.TV_raffleid_list)
if self.bilibili.TV_raffleid_list:
for i in range(0, len(self.bilibili.TV_roomid_list)):
url="http://api.live.bilibili.com/gift/v2/smalltv/notice?roomid="+str(self.bilibili.TV_roomid_list[0])+"&raffleId="+str(self.bilibili.TV_raffleid_list[0])
headers = {
'Accept': 'application/json, text/plain, */*',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36',
'Accept-Language': 'zh-CN,zh;q=0.9',
'accept-encoding': 'gzip, deflate',
'Host': 'api.live.bilibili.com',
'cookie': self.bilibili.cookie,
}
response = requests.get(url, headers=headers)
if response.json()['data']['gift_name'] != "":
try:
print("# 房间", str(self.bilibili.TV_roomid_list[0]).center(9), "小电视道具抽奖结果:", (response.json()['data']['gift_name'])+"x"+str(response.json()['data']['gift_num']))
del self.bilibili.TV_roomid_list[0]
del self.bilibili.TV_raffleid_list[0]
del self.bilibili.TV_time_list[0]
except:
pass
await asyncio.sleep(60)

bilibili().clean_TV()


# print('自动延迟参数', sleeptime1, sleeptime2)
await asyncio.sleep(30)
'''
if sleeptime1 != None and sleeptime2 != None:
# print(sleeptime1, sleeptime2)
await asyncio.sleep(min(sleeptime1, sleeptime2))
elif sleeptime1 == None and sleeptime2 == None:
await asyncio.sleep(60)
elif sleeptime1 != None:
# print(sleeptime1)
await asyncio.sleep(sleeptime1)
else:
# print(sleeptime2)
await asyncio.sleep(sleeptime2)
'''
47 changes: 14 additions & 33 deletions OnlineHeart.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,29 @@
import datetime
import asyncio

def CurrentTime():
currenttime = int(time.mktime(datetime.datetime.now().timetuple()))
return str(currenttime)


class OnlineHeart():

def __init__(self, bilibili):
self.bilibili = bilibili
# 发送pc心跳包 //好像有点bug???
def pcpost_heartbeat(self):
url = 'http://api.live.bilibili.com/User/userOnlineHeart'
response = requests.post(url, headers=self.bilibili.pcheaders)
#print(response.json())

# 发送app心跳包
def apppost_heartbeat(self):
time = self.CurrentTime()
temp_params = 'access_key=' + self.bilibili.access_key + '&actionKey=' + self.bilibili.actionKey + '&appkey=' + self.bilibili.appkey + '&build=' + self.bilibili.build + '&device=' + self.bilibili.device + '&mobi_app=' + self.bilibili.mobi_app + '&platform=' + self.bilibili.platform + '&ts=' + time
params = temp_params + self.bilibili.app_secret
hash = hashlib.md5()
hash.update(params.encode('utf-8'))
url = 'https://api.live.bilibili.com/mobile/userOnlineHeart?' + temp_params + '&sign=' + str(hash.hexdigest())
payload = {'roomid': 23058, 'scale': 'xhdpi'}
response = requests.post(url, data=payload, headers=self.bilibili.appheaders)
#print("app端心跳状态:" + response.json()['message'])
bilibili().apppost_heartbeat()

def pcpost_heartbeat(self):
bilibili().pcpost_heartbeat()

# 心跳礼物 //测试功能
def heart_gift(self):
url = "https://api.live.bilibili.com/gift/v2/live/heart_gift_receive?roomid=3&area_v2_id=34"
response = requests.get(url, headers=self.bilibili.pcheaders)
#print(response.json())
bilibili().heart_gift()

# 获取当前系统时间的unix时间戳
def CurrentTime(self):
currenttime = str(int(time.mktime(datetime.datetime.now().timetuple())))
return currenttime

# 因为休眠时间差不多,所以放到这里,此为实验性功能
def draw_lottery(self):
for i in range(60,80):
url = "https://api.live.bilibili.com/lottery/v1/box/getStatus?aid="+str(i)
response = requests.get(url,headers=self.bilibili.pcheaders)
response = bilibili().get_lotterylist(i)
res = response.json()
#print(res)
if res['code'] == 0:
temp = response.json()['data']['title']
if "测试" in temp:
Expand All @@ -56,11 +38,9 @@ def draw_lottery(self):
for g in range(0, check):
join_end_time = response.json()['data']['typeB'][g]['join_end_time']
join_start_time = response.json()['data']['typeB'][g]['join_start_time']
ts = self.CurrentTime()
ts = CurrentTime()
if int(join_end_time) > int(ts) > int(join_start_time):
url1 = 'https://api.live.bilibili.com/lottery/v1/box/draw?aid=' + str(i) + '&number=' + str(
g + 1)
response1 = requests.get(url1, headers=self.bilibili.pcheaders)
response1 = bilibili().get_gift_of_lottery(i, g)
print("当前时间:", time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
print("参与抽奖回显:",response1.json())
else:
Expand All @@ -73,8 +53,9 @@ async def run(self):
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "心跳")
self.apppost_heartbeat()
self.pcpost_heartbeat()
self.heart_gift()
self.heart_gift()
self.draw_lottery()
# print('OnlineHeart is over')
await asyncio.sleep(300)


Loading

0 comments on commit a818e71

Please sign in to comment.