-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
70 lines (50 loc) · 2.18 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
from appendImage import append_page, append_puzzle_page
from index import create_title_page
from generatePuzzle import create_all_puzzles, create_individual_puzzle
from Words.rawWordToJSON import word_to_json
# Global book_name
book_name = "Where's Word-o"
def main():
global book_name
image_path = "Assets/Cover.png"
background_image = "Assets/Background.png"
puzzle_background_image = "Assets/pageBackground.png"
word_json_path = "Words/words.json"
puzzle_folder = "generated_puzzles"
print(f"Creating book '{book_name}'.\n\n")
start_puzzle = input("Enter the puzzle number to start from (default 1): ").strip() or "1"
if not start_puzzle.isdigit():
print("Invalid puzzle number. Exiting...")
return
start_puzzle = int(start_puzzle)
delete_puzzles = input("Delete puzzles after making the book? (y/n, default n): ").strip().lower() or 'n'
if delete_puzzles not in ['y', 'n']:
print("Invalid input. Exiting...")
return
if start_puzzle == 1:
print("Adding cover image.\n")
append_page(book_name, image_path)
print("Creating title page.\n")
create_title_page(book_name, word_json_path,
background_image=background_image)
print("Converting raw words to JSON.\n")
word_to_json(file_path="Words/words.txt")
print("\nGenerating puzzles and adding to the book.")
fail_count = create_all_puzzles(
word_json_path, puzzle_background_image, puzzle_folder, start_puzzle)
if fail_count:
print(f"Failed to create {fail_count} puzzle(s).")
create_individual_puzzle(
fail_count, word_json_path, puzzle_folder, background_image=puzzle_background_image)
print("All puzzles are made. Adding to the book...")
append_puzzle_page(f"{book_name}.pdf", puzzle_folder,
background_image=puzzle_background_image)
print("All puzzles added to the book.")
if delete_puzzles == 'y':
print("Deleting puzzles...")
import shutil
shutil.rmtree(puzzle_folder)
print("Puzzles deleted.")
print(f"Book '{book_name}' created successfully.")
if __name__ == '__main__':
main()