forked from Dawnnnnnn/bilibili-live-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Silver.py
84 lines (78 loc) · 3.85 KB
/
Silver.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
from bilibili import bilibili
import hashlib
import requests
import datetime
import time
import asyncio
class Silver(bilibili):
# 获取当前系统时间的unix时间戳
def CurrentTime(self):
currenttime = str(int(time.mktime(datetime.datetime.now().timetuple())))
return currenttime
# 将time_end时间转换成正常时间
def DataTime(self):
datatime = str(datetime.datetime.fromtimestamp(float(self.time_end())))
return datatime
# 领瓜子时判断领取周期的参数
def time_start(self):
time = self.CurrentTime()
temp_params = 'access_key=' + self.access_key + '&actionKey=' + self.actionKey + '&appkey=' + self.appkey + '&build=' + self.build + '&device=' + self.device + '&mobi_app=' + self.mobi_app + '&platform=' + self.platform + '&ts=' + time
params = temp_params + self.app_secret
hash = hashlib.md5()
hash.update(params.encode('utf-8'))
GetTask_url = 'https://api.live.bilibili.com/mobile/freeSilverCurrentTask?' + temp_params + '&sign=' + str(
hash.hexdigest())
response = requests.get(GetTask_url,headers=self.appheaders)
temp = response.json()
# print (temp['code']) #宝箱领完返回的code为-10017
if temp['code'] == -10017:
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "今日宝箱领取完毕")
else:
time_start = temp['data']['time_start']
return str(time_start)
# 领瓜子时判断领取周期的参数
def time_end(self):
try:
time = self.CurrentTime()
temp_params = 'access_key=' + self.access_key + '&actionKey=' + self.actionKey + '&appkey=' + self.appkey + '&build=' + self.build + '&device=' + self.device + '&mobi_app=' + self.mobi_app + '&platform=' + self.platform + '&ts=' + time
params = temp_params + self.app_secret
hash = hashlib.md5()
hash.update(params.encode('utf-8'))
GetTask_url = 'https://api.live.bilibili.com/mobile/freeSilverCurrentTask?' + temp_params + '&sign=' + str(
hash.hexdigest())
response = requests.get(GetTask_url, headers=self.appheaders)
temp = response.json()
time_end = temp['data']['time_end']
return str(time_end)
except:
pass
# 领取银瓜子
def GetAward(self):
try:
time = self.CurrentTime()
timeend = self.time_end()
print("hello")
timestart = self.time_start()
temp_params = 'access_key=' + self.access_key + '&actionKey=' + self.actionKey + '&appkey=' + self.appkey + '&build=' + self.build + '&device=' + self.device + '&mobi_app=' + self.mobi_app + '&platform=' + self.platform + '&time_end=' + timeend + '&time_start=' + timestart + '&ts=' + time
params = temp_params + self.app_secret
hash = hashlib.md5()
hash.update(params.encode('utf-8'))
url = 'https://api.live.bilibili.com/mobile/freeSilverAward?' + temp_params + '&sign=' + str(
hash.hexdigest())
response = requests.get(url, headers=self.appheaders)
#print(response.json())
return response.json()['code']
except:
pass
async def run(self):
while 1:
temp = self.GetAward()
if temp == None or temp == -10017:
print("# 半小时后检测是否第二天了")
await asyncio.sleep(1800)
elif temp == 0:
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "打开了宝箱")
self.GetAward()
else:
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "继续等待宝箱冷却...")
await asyncio.sleep(181)