-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
30 lines (22 loc) · 991 Bytes
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import sys
from typing import OrderedDict
import xml.etree.ElementTree as ET
def get_value_from_list_of_tuples_by_key(tuples_list, key_to_find):
for key, value in tuples_list:
if(key==key_to_find):
return value
def get_timeouts_from_current_half(root, team_shortname):
timeouts = 0
period = get_value_from_list_of_tuples_by_key(root.find('status').items(), 'period')
if(int(period) < 3):
periods = ['1', '2']
else:
periods = ['3', '4', '5', '6', '7']
for quarter_plays in root.findall(f"./plays/period"):
if(get_value_from_list_of_tuples_by_key(quarter_plays.items(), 'number') in periods):
for play in quarter_plays.findall('play'):
if(get_value_from_list_of_tuples_by_key(play.items(), 'action') == "TIMEOUT"):
timeouts += 1
return timeouts
if __name__== "__main__":
print(get_timeouts_from_current_half(ET.parse(sys.argv[1]).getroot()))