-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
96 lines (85 loc) · 3.05 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
from threading import Thread
from utils import (
check_bingos_and_write_to_output,
generate_and_return_details,
read_from_input,
generate_multiple_cards,
update_config_one_attr,
)
# do enums idk
class autobingo:
def __init__(
self,
driver: str = "chrome",
cards_path="cards.txt",
input_path="input.txt",
url: str = "",
output_path="output.json",
gamemode: str = "normal",
reverse: bool = False,
start: int = 0,
free_space: str = "no credit",
free_space_in_middle: bool = False,
headless: bool = True,
size: int = 5,
bingo_id: str = "",
num_of_threads: int = 7,
) -> None:
"""
driver : selenium.webdriver
url : string of the bingomaker.com generator url
cards_location : where the cards links will be stored
input_phrases : where the input phrases to search for will be stored
output_path : where the bingo'ed cards' links will be stores [will be automatically created if not provided]
size must be odd
"""
# turn input phrases file path into list of strings
# dont mention input_path or cards_path if you're using the generate function
self.num_of_threads = num_of_threads
self.free_space_in_middle = free_space_in_middle
self.size = size
self.input_path = input_path
self.cards_path = cards_path
self.start = start
self.free_space = free_space
self.reverse = reverse
self.gamemode = gamemode
self.driver = driver
self.url = url
self.output_path = output_path
self.headless = headless
self.bingo_id = bingo_id
if gamemode == "3in6":
self.size = 6
update_config_one_attr("size", 6)
update_config_one_attr("free_space_in_middle", False)
print("Updating size to 6 and free space in middle for 3in6 gamemode")
def create_cards(self, num: int) -> None:
"""
creates num cards and writes their links to the cards.txt file
"""
# check for the first card to update the details
if self.url == "":
raise ValueError("generate url not provided")
generate_and_return_details(self, 0)
threads = []
for _ in range(self.num_of_threads):
t = Thread(
target=generate_multiple_cards,
args=(self, int(num / self.num_of_threads)),
)
t.daemon = True
threads.append(t)
for thread in threads:
thread.start()
for thread in threads:
thread.join()
def check_bingo_of_all_cards(self) -> None:
"""
checks bingo for all cards in the cards.txt file
"""
# innit the reading and changing of the files
self.input_phrases = read_from_input(self)
for indx, phrase in enumerate(self.input_phrases):
self.input_phrases[indx] = phrase.lower()
check_bingos_and_write_to_output(self)