This repository has been archived by the owner on Sep 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
bliveaward.py
62 lines (53 loc) · 2.11 KB
/
bliveaward.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# pylint: disable=I0011,C0103,C0111
from __future__ import print_function
from time import time, sleep
import requests
from utils import APP_KEY, headers, getSign
_logger = None
def setLogger(logger):
global _logger
_logger = logger
def main(ACCESS_KEY):
errCount = 0
for _ in range(32):
params = {'access_key': ACCESS_KEY, 'appkey': APP_KEY, 'actionKey': 'appkey', 'build': '5370000', 'channel': 'bilih5', 'device': 'android', 'mobi_app': 'android', 'platform': 'android'}
params['ts'] = str(int(time()))
params['sign'] = getSign(params)
r = requests.get('https://api.live.bilibili.com/mobile/freeSilverCurrentTask',
params=params, headers=headers) # or 'https://api.live.bilibili.com/lottery/v1/SilverBox/getCurrentTask'
_logger.debug(r.text)
res = r.json()
if res['code'] == 0:
wait = res['data']['time_end'] - time() + 5
if wait > 0:
_logger.info('Waiting for %d seconds' % wait)
sleep(wait)
params['time_start'] = res['data']['time_start']
params['time_end'] = res['data']['time_end']
params.pop('sign')
params['ts'] = str(int(time()))
params['sign'] = getSign(params)
r = requests.get('https://api.live.bilibili.com/mobile/freeSilverAward',
params=params, headers=headers)
_logger.debug(r.text)
j = r.json()
if j['code'] != 0:
errCount += 1
_logger.info(res['message'])
sleep(5)
else:
errCount += 1
_logger.error('freeSilverCurrentTask returned error! Error message:' + res['message'])
if res['code'] == -10017:
return
if res['code'] == -101 or json['code'] == -500: # Not login
return 1 # Restart
sleep(5)
if errCount >= 5:
return
if __name__ == '__main__':
from logger import getLogger
setLogger(getLogger())
main('ACCESS_KEY')