Под списками есть список идентификаторов команд.Я пытаюсь перебрать team_id для детей, у которых есть дополнительные атрибуты, и найти их с возрастом 1.
Я выяснил, как получить доступ к team_id, но не могу понять, какОбведите каждого участника и подсчитайте, сколько из них соответствует требованиям.
roster_info_snapshot = cfm.child('rosters').child(team_id).get()
Это код, который у меня сейчас работает, который возвращает количество травмированных игроков в команде.
# Number of injured players
elif data['name'] != 'John Madden' and '/injuries' in data['text'].lower():
print('Injuries keyword found')
msg = data['text'].lower().split()
func_index = msg.index('/injuries')
if(len(msg) > func_index + 1):
try:
print(f'Retrieving injuries info for {msg[func_index + 1]}')
team_map_snapshot = cfm.child('teamMap').get()
team_id = team_map_snapshot[msg[func_index + 1].lower()]
team_info_snapshot = cfm.child('teams').child(team_id).get()
msg = f"{data['name']}, you sent '{data['text']}'"
send_message(f"{team_info_snapshot['displayName']} have {team_info_snapshot['ovrRating']} players injured")
except Exception as e:
print(e)
send_message('Sorry, an error occurred processing your request.')
else:
send_message("Sorry, I couldn't find a team name associated with your request."
" Use '/help' to get a list of commands.")
return 'ok', 200
