From 3222f6e7cdf9f0ba0df3c3e4916f785c09e820ab Mon Sep 17 00:00:00 2001 From: zhonghuaifang <56331610+zhonghuaifang@users.noreply.github.com> Date: Tue, 7 Feb 2023 09:02:18 +0800 Subject: [PATCH] Update bika.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 加入当前经验和等级通知 --- function/bika/bika.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/function/bika/bika.py b/function/bika/bika.py index 9ceb1b0..93ee347 100644 --- a/function/bika/bika.py +++ b/function/bika/bika.py @@ -1,10 +1,10 @@ +from http import client +from sendNotify import * import random import string import sys sys.path.append("My-Actions/function/bika/") -from sendNotify import * -from http import client sendNotify = sendNotify() @@ -17,7 +17,9 @@ pica_api_base_url = "https://%s/" % pica_api_host sign_in_path = "auth/sign-in" punch_in_path = "users/punch-in" +profile_path = "/users/profile" POST = "POST" +GET = "GET" # noinspection SpellCheckingInspection api_key = "C69BAF41DA5ABD1FFEDC6D2FEA56B" @@ -38,7 +40,8 @@ def send_request(path: string, method: string, body: string = None, token: string = None) -> dict: current_time = str(int(time.time())) - nonce = "".join(random.choices(string.ascii_lowercase + string.digits, k=32)) + nonce = "".join(random.choices( + string.ascii_lowercase + string.digits, k=32)) raw = path + current_time + nonce + method + api_key raw = raw.lower() h = hmac.new(api_secret.encode(), digestmod=hashlib.sha256) @@ -77,6 +80,10 @@ def punch_in(token: string): return send_request(punch_in_path, POST, token=token) +def profile(token: string): + return send_request(profile_path, GET, token=token) + + if __name__ == '__main__': if os.environ['BIKA_USER'] == "" or os.environ['BIKA_PASS'] == "": print("未填写哔咔账号密码 取消运行") @@ -91,5 +98,15 @@ def punch_in(token: string): msg = '重复签到 - Already punch-in' print(msg) + profile_msg = '' + profile_response = profile(current_token) + if profile_response["code"] == "200": + profile_result = profile_response["data"]["user"] + profile_msg = ( + "\n用户名: %s" % profile_result["name"], + "\n等级: %s" % profile_result["level"], + "\n经验: %s" % profile_result["exp"], + ) + if SEND_KEY == '': - sendNotify.send(title=u"哔咔漫画自动打哔咔", msg="【哔咔漫画自动签到】\n" + msg) + sendNotify.send(title=u"哔咔漫画自动打哔咔", msg="【哔咔漫画自动签到】\n" + msg+profile_msg)