forked from INF142/team-local-tactics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchamplistloader.py
38 lines (29 loc) · 1.04 KB
/
champlistloader.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
31
32
33
34
35
36
37
38
from core import Champion
def _parse_champ(champ_text: str) -> Champion:
name, rock, paper, scissors = champ_text.split(sep=',')
return Champion(name, float(rock), float(paper), float(scissors))
def champ_to_dict(text: str) -> dict[str, Champion]:
champions = {}
for line in text.split("\n"):
champ = _parse_champ(line)
champions[champ.name] = champ
return champions
def from_csv(filename: str) -> dict[str, Champion]:
champions = {}
with open(filename, 'r') as f:
for line in f.readlines():
champ = _parse_champ(line)
champions[champ.name] = champ
return champions
def from_csv2str(filename: str) -> str:
champs = ""
with open(filename, 'r') as f:
for line in f.readlines():
champs = champs+line
return champs
def load_some_champs():
return from_csv('some_champs.txt')
def load_champs_string():
return from_csv2str('some_champs.txt')
def load_loserlog():
return from_csv2str('loserlog.txt')