ChenyuRabbitLove commited on
Commit
cfdf3bc
1 Parent(s): 97cd51a

fix: modify get_player_info function

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import json
 
2
 
3
  import gradio as gr
4
 
@@ -20,12 +21,14 @@ seafoam = Seafoam()
20
  def get_player_info(player_backend_user_id):
21
  with open("latest_player_data.json", "r", encoding="utf-8") as file:
22
  player_info = json.load(file)
23
- try:
24
- player_info = player_info[player_backend_user_id]
25
- return player_info
26
- except KeyError:
27
- player_info = Player(player_backend_user_id=player_backend_user_id, init=True)
28
- return player_info.to_dict()
 
 
29
 
30
 
31
  # start of gradio interface
 
1
  import json
2
+ import logging
3
 
4
  import gradio as gr
5
 
 
21
  def get_player_info(player_backend_user_id):
22
  with open("latest_player_data.json", "r", encoding="utf-8") as file:
23
  player_info = json.load(file)
24
+
25
+ if player_backend_user_id in player_info:
26
+ return player_info[player_backend_user_id]
27
+ else:
28
+ logging.info(f"No data found for player ID {player_backend_user_id}. Initializing new player data.")
29
+
30
+ new_player = Player(player_backend_user_id=player_backend_user_id, init=True)
31
+ return new_player.to_dict()
32
 
33
 
34
  # start of gradio interface