From 0d6d40b0d1a15a30631df72f4485b1996b668d25 Mon Sep 17 00:00:00 2001 From: Yang Changeun Date: Wed, 13 Mar 2024 14:52:03 +0900 Subject: [PATCH] Fixed conflicts with other unintended games --- main.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index aeeb2fd..a600c78 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ game_code = '26' # Game Code +# 1 : Honkai Impact 3rd # 2 : Genshin Impact # 6 : Honkai: Star Rail @@ -13,6 +14,19 @@ gh_token = os.environ['GH_TOKEN'] gist_id = os.environ['GIST_ID'] +def get_only_data_needed(userInfoInGame, list_to_return) : + + list_to_return[-1].append(str(userInfoInGame['level'])) + for eachData in userInfoInGame['data'] : + if 'Active' in eachData['name'] : + list_to_return[-1].append(eachData['value']) + elif 'Characters' in eachData['name'] : + list_to_return[-1].append(eachData['value']) + elif 'Achievements' in eachData['name'] : + list_to_return[-1].append(eachData['value']) + + return list_to_return + def get_data_from_hoyolab(hoyo_uid, hoyo_token) : headers = { @@ -31,16 +45,10 @@ def get_data_from_hoyolab(hoyo_uid, hoyo_token) : for eachGame in jsonData['data']['list'] : if eachGame['game_id'] == 2 : return_list.append(['Genshin Impact']) + return_list = get_only_data_needed(eachGame, return_list) elif eachGame['game_id'] == 6 : return_list.append(['Honkai: Star Rail']) - return_list[-1].append(str(eachGame['level'])) - for eachData in eachGame['data'] : - if 'Active' in eachData['name'] : - return_list[-1].append(eachData['value']) - elif 'Characters' in eachData['name'] : - return_list[-1].append(eachData['value']) - elif 'Achievements' in eachData['name'] : - return_list[-1].append(eachData['value']) + return_list = get_only_data_needed(eachGame, return_list) return return_list else : return 'Error occured'