generated from Code-Institute-Org/python-essentials-template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun.py
169 lines (129 loc) · 4.51 KB
/
run.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
from art import tprint
import os
from time import sleep
from termcolor import colored, cprint
import gdrive_utility
from helpers import ask_any_key, ask_yes_no, clear, current_hour
from create_gform import create_google_form
from create_quiz import *
from play_quiz import *
if os.path.exists("env.py"):
import env # noqa
# Password for Secret Google Drive Utility
SECRET = os.environ.get("ADMIN")
def pick_greeting(hour):
"""
Returns a suitable greeting for the time of day.
Args:
hour: The current hour in 24hr time format
"""
if hour < 6:
return "Wow, you're up late!"
elif hour < 11:
return "Good morning!"
elif hour < 17:
return "Good afternoon,"
else:
return "Good evening,"
greeting = pick_greeting(current_hour)
def main():
"""
Code to run on terminal boot
"""
menu_options = ["(1) Play Quick Quiz Round",
"(2) Create Custom Quiz",
"(3) Create a Google Form Quiz",
"(4) Help"]
help_text = ["""How to Use Quiz Master 2022 \n \n
With Quiz Master 2022, you can create and play multiple choice quiz games
either to play here in the terminal, or export as a Google Form that
you can send to your friends - perfect for running an online table quiz!
(1) Quick Quiz Round \n
Play a short Quiz of 8 General Knowledge Questions here in the terminal.
Chose an answer with the keys 1, 2, 3 or 4 and hit Enter.
""",
"""
(2) Create Custom Quiz
Choose custom settings such as categories, number of questions and
difficulty and play here in the terminal.
(3) Create a Google Form Quiz
Choose custom settings, and then export your Quiz to a Google Form
you can share with your friends.
You can input your e-mail address and see the results as your friends
submit their answers!
Enter "Quit" or "Q" at any time to return to the Main Menu.
See this project on GitHub at https://github.com/davidindub/quiz-master
Quiz Master 2022 © David Kelly.
"""]
clear()
tprint(" QUIZ\nMASTER\n 2022", font="o8")
cprint(f"{greeting} Welcome to Quiz Master 2022! \n", "blue")
sleep(2)
while True:
clear()
# Main Menu:
cprint("Main Menu", "white", "on_blue")
print("_________\n")
try:
print("Please choose from the following:\n")
for option in menu_options:
print(option)
response = int(
input("\nPress Enter to confirm your selection. \n"))
except ValueError:
clear()
continue
if response == 1:
# Creates a quiz round of 8 easy general knowledge questions
quick_quiz = Game("Quick Quiz", 1, 8, [9], "easy")
# Play the Quiz Game
while True:
play_terminal_quiz(quick_quiz)
break
continue
if response == 2:
# Prompts the user to set up their quiz
custom_quiz = setup_new_quiz()
# Play the Quiz the user just set up
if custom_quiz:
play_terminal_quiz(custom_quiz)
continue
if response == 3:
print("OK you want to make a Google For Quiz"
" to share with friends")
google_quiz = setup_new_quiz()
try:
create_google_form(google_quiz)
except Exception:
cprint("There was an error with the Google Form API\n", "red")
print("Please try again later.")
continue
if response == 4:
clear()
tprint("HELP", font="o8")
print(help_text[0])
cprint("Press any key to read more.", "white", "on_blue")
input()
clear()
print(help_text[1])
ask_any_key()
continue
if response == 999:
clear()
cprint("\nGoogle Drive Utility Login", "blue")
x = input("What is the password?\n")
if x == SECRET:
cprint("✅ Correct! Loading Google Drive Management...\n",
"green")
sleep(1)
clear()
gdrive_utility.run()
continue
else:
cprint("❌ Incorrect Password", "red")
continue
if response not in [1, 2, 3, 4, 999] or input == "":
continue
else:
break
main()