-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject.py
More file actions
84 lines (66 loc) · 2.13 KB
/
project.py
File metadata and controls
84 lines (66 loc) · 2.13 KB
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
import random
import pdfkit
import csv
import sys
from tabulate import tabulate
def main():
try:
chosen_recipe = ask_for_input()
print("Loading please wait...")
match chosen_recipe:
case 1:
gen_rand_african_dish()
case 2:
gen_rand_european_dish()
case 3:
gen_rand_latin_dish()
case 4:
gen_rand_asian_dish()
case _:
sys.exit("That is not an available option!")
print("Done! Please check the \"generated_recipe\" pdf for your recipe!\nEnjoy! 😄")
except ValueError:
sys.exit("Please make sure to provide a numerical input only!")
def ask_for_input():
options = [
["Nationality", "Number"],
["African", 1],
["European", 2],
["Latin", 3],
["Asian",4]
]
table = tabulate(options, headers="firstrow", tablefmt="fancy_grid")
return int(input(f"What type of recipe would you like?\n {table}\n"))
def gen_pdf(s):
config = pdfkit.configuration(wkhtmltopdf='/usr/bin/wkhtmltopdf')
pdfkit.from_url(s, 'generated_recipe.pdf', configuration=config)
def read_csv(c):
list = []
with open(c, 'r') as file:
reader = csv.reader(file)
next(reader)
for recipe in reader:
list.append(recipe)
return list
def gen_rand_african_dish():
african = read_csv("african.csv")
randint: int = random.randint(0, len(african))
recipe: str = african[randint]
return gen_pdf(recipe)
def gen_rand_european_dish():
european = read_csv("european.csv")
randint: int = random.randint(0, len(european))
recipe: str = european[randint]
return gen_pdf(recipe)
def gen_rand_latin_dish():
latin = read_csv("latin.csv")
randint: int = random.randint(0, len(latin))
recipe: str = latin[randint]
return gen_pdf(recipe)
def gen_rand_asian_dish():
asian = read_csv("asian.csv")
randint: int = random.randint(0, len(asian))
recipe: str = asian[randint]
return gen_pdf(recipe)
if __name__ == "__main__":
main()