From 1a21bc8c15c69fe44a3920d1ed6158a890c54787 Mon Sep 17 00:00:00 2001 From: nico <13307130285@fudan.edu.cn> Date: Sun, 25 Mar 2018 11:23:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=BC=80=E4=BA=86=E7=BB=9F=E4=B8=80api?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=EF=BC=8C=E5=AE=9E=E7=8E=B0=E4=BA=86=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=E8=AE=B0=E5=BD=95post?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 。 --- API.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 API.py diff --git a/API.py b/API.py new file mode 100644 index 0000000..65cff94 --- /dev/null +++ b/API.py @@ -0,0 +1,17 @@ +from bilibili import bilibili +import requests + + +class API(bilibili): + # 本函数只是实现了直播观看历史里的提交,与正常观看仍有区别!! + # 其实csrf_token就是用了token,我懒得再提出来了 + # 就是Login函数里面的cookie[0]['value'] + def post_watching_history(csrf_token, room_id): + data = { + "room_id": room_id, + "csrf_token": csrf_token + } + ulr = "https://api.live.bilibili.com/room/v1/Room/room_entry_action" + response = requests.post(ulr, data=data, headers=bilibili.pcheaders) + # print(response.json()) + return 0 From ea6fdc5b7545c309f9fad0705542d4a27838c4dc Mon Sep 17 00:00:00 2001 From: nico <13307130285@fudan.edu.cn> Date: Sun, 25 Mar 2018 16:03:27 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=9F=A5=E8=AF=A2=E5=8F=AF=E7=94=A8?= =?UTF-8?q?=E7=A4=BC=E7=89=A9api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 。 --- API.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/API.py b/API.py index 65cff94..deb4bc6 100644 --- a/API.py +++ b/API.py @@ -1,5 +1,7 @@ from bilibili import bilibili import requests +import datetime +import time class API(bilibili): @@ -11,7 +13,20 @@ def post_watching_history(csrf_token, room_id): "room_id": room_id, "csrf_token": csrf_token } - ulr = "https://api.live.bilibili.com/room/v1/Room/room_entry_action" - response = requests.post(ulr, data=data, headers=bilibili.pcheaders) + url = "https://api.live.bilibili.com/room/v1/Room/room_entry_action" + requests.post(url, data=data, headers=bilibili.pcheaders) # print(response.json()) return 0 + + def CurrentTime(): + currenttime = str(int(time.mktime(datetime.datetime.now().timetuple()))) + return currenttime + + def get_bag_list(): + url = "https://api.live.bilibili.com/gift/v2/gift/m_bag_list?" + 'access_key='+bilibili.access_key+'&actionKey='+bilibili.actionKey+'&appkey='+bilibili.appkey+'&build='+bilibili.build+'&device='+bilibili.device + '&mobi_app='+bilibili.mobi_app+'&platform='+bilibili.platform + '&ts=' + API.CurrentTime() + response = requests.get(url, headers=bilibili.pcheaders) + for i in range(len(response.json()['data'])): + gift_name = response.json()['data'][i]['gift_name'] + gift_num = str(response.json()['data'][i]['gift_num']).center(4) + expireat = str(round(int(response.json()['data'][i]['expireat']) / 86400, 1)).center(6) + print(gift_name, 'X', gift_num, '(在', expireat, '天后过期)')