forked from Dawnnnnnn/bilibili-live-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Silver.py
60 lines (53 loc) · 1.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
from bilibili import bilibili
import hashlib
import requests
import datetime
import time
import asyncio
class Silver():
# 将time_end时间转换成正常时间
def DataTime(self):
datatime = str(datetime.datetime.fromtimestamp(float(self.time_end())))
return datatime
# 领瓜子时判断领取周期的参数
def time_start(self):
response = bilibili().get_time_about_silver()
temp = response.json()
# print (temp['code']) #宝箱领完返回的code为-10017
if temp['code'] == -10017:
print("# 今日宝箱领取完毕")
else:
time_start = temp['data']['time_start']
return str(time_start)
# 领瓜子时判断领取周期的参数
def time_end(self):
try:
response = bilibili().get_time_about_silver()
temp = response.json()
time_end = temp['data']['time_end']
return str(time_end)
except:
pass
# 领取银瓜子
def GetAward(self):
try:
timeend = self.time_end()
timestart = self.time_start()
response = bilibili().get_silver(timestart, timeend)
#print(response.json())
return response.json()['code']
except:
pass
async def run(self):
while 1:
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())), "检查宝箱状态")
temp = self.GetAward()
if temp == None or temp == -10017:
#print("# 半小时后检测是否第二天了")
await asyncio.sleep(1800)
elif temp == 0:
print("# 打开了宝箱")
self.GetAward()
else:
print("# 继续等待宝箱冷却...")
await asyncio.sleep(181)