-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
39 lines (31 loc) · 1.41 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
import sys
from typing import Iterable, SupportsInt
from datetime import date
from itertools import repeat
from urllib.request import urlopen
from teams import get_teams_file
from simulator import Team, better_grouper_two
gender = 'm'
if '-w' in sys.argv:
gender = 'w'
elif '-m' in sys.argv:
gender = 'm'
TEAMS_FILENAME = f'teams_{date.today().year}{gender}.json'
def randomnumbers():
for x in urlopen('https://www.random.org/integers/?num=63&min=0&max=999&col=1&base=10&format=plain&rnd=new'):
yield int(x)
if '--test' in sys.argv:
random_generator = repeat(0)
else:
print("Using numbers generated by random.org. Do not use faster than you could manually refresh a webpage, there is a quota per IP address per day, and you are otherwise subject to their guidelines at random.org/clients")
random_generator = randomnumbers()
divisions = get_teams_file(TEAMS_FILENAME)
division_matchups = better_grouper_two(d.name for d in divisions)
final_four = {division.name: division.play_through(random_generator)
for division in divisions}
championship = [Team.play_game(final_four[div_a], final_four[div_b],
next(random_generator))
for div_a, div_b in division_matchups]
champion = Team.play_game(*championship, next(random_generator))
print("\n\nFinalFour\n" + championship[0].name + ", " + championship[1].name)
print("\nChamp: " + champion.name)