-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
122 lines (92 loc) · 3.04 KB
/
main.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import os
import pandas as pd
from string import capwords
from predictor import get_teams_from_season, predictor, output_previous_prediction
from cli import clear, selection, log, log_invalid_selection
from data_scraper.api_data_scraper import Scraper
import data_scraper.json_data_processor as json_data_processor
os.makedirs(f"./data/csv_datasets/epl", exist_ok=True)
os.makedirs(f"./data/raw_datasets/epl", exist_ok=True)
def scrape_data(seasons: list):
log("Scraping data from the API...")
for season in seasons:
scraper = Scraper(season)
scraper.scrape()
log("Data has been scraped for the specified seasons")
output_data()
merge_data()
return
def output_data():
log("Processing Data...")
files = os.listdir("./data/raw_datasets/epl")
for file in files:
file_name = os.path.join(file).split(".")[0]
data = json_data_processor.load_raw_dataset(file_name)
json_data_processor.output_dataset(file_name, data)
return
def merge_data():
log("Data has been processed and output")
files = os.listdir("./data/csv_datasets/epl")
df_concat = pd.concat([pd.read_csv(f"./data/csv_datasets/epl/{file}") for file in files if file != "all_seasons.csv"], ignore_index=True)
df_concat.to_csv(f"./data/csv_datasets/epl/all_seasons.csv", index=False)
return
def pause():
os.system('pause')
clear()
def interface():
while True:
module = selection()
if module == "0":
quit()
elif module == "1":
clear()
scrape_data(
[
"2016",
"2017",
"2018",
"2019",
"2020",
"2021",
"2022"
]
)
pause()
elif module == "2":
clear()
scrape_data(
[
"2022"
]
)
pause()
elif module == "3":
home_team, away_team = prediction_interface()
predictor(home_team, away_team)
pause()
elif module == "4":
output_previous_prediction()
pause()
else:
log_invalid_selection()
def prediction_interface():
teams = get_teams_from_season(season=2022)
while True:
clear()
print("AVAILABLE TEAMS\n")
log(teams)
home_team = capwords(input("ENTER HOME TEAM\n"))
if home_team not in teams:
log_invalid_selection()
continue
away_team = capwords(input("\nENTER AWAY TEAM\n"))
if away_team not in teams:
log_invalid_selection()
continue
if home_team == away_team:
log_invalid_selection()
continue
print("")
return home_team, away_team
if __name__ == "__main__":
interface()