-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
159 lines (135 loc) · 4.6 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
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
import os
import sys
from api import *
import logging
import inquirer
from halo import Halo
from typing import Union
from api import api_generic
EVENT_POSTS_TYPES = {
"type": ["post", "story", "description"],
"post": ["workshop", "generated_image"],
"story": ["classic", "reminder", "citation", "poll", "quiz", "question"],
"lab": ['IA', 'Cyber', 'Coder', 'Meta', 'Blockchain', 'Maker'],
"info": ["event_name", "description", "date", "hour", "location"]
}
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
class Colors:
"""
This class is an Enum that keep all the colors to use in our CLI interface.
"""
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
class CLI:
def __init__(self):
start = self.menu(
title="Menu d'accueil",
message="Choissisez une option dans le menu d'accueil",
opt={
"Générer Créa": self.event,
"Setup": self.setup,
"Quitter": "quit"
}
)
start()
def setup(self):
pass
def menu(self, title: str, message: str, opt: dict) -> Union[classmethod, str]:
"""
Crée un menu carousel avec différentes options.
:param title: Titre du menu (pas affiché)
:param message: Description du message (affiché)
:param opt: Dictionnaire d'options (clé: Message affiché, valeur: Appel de la fonction)
:rtype: Valeur de l'objet sélectionné parmi opt
"""
options = [
inquirer.List(title,
message=message,
choices=list(opt.keys()),
carousel=True, )
]
answer = inquirer.prompt(options)[title]
return opt.get(answer, lambda: "Indisponible")
def event(self):
self.menu(
title="type",
message="Choissisez un type de créa",
opt={
"Post": self.post,
"Story": self.story,
"Description": self.description,
"[BLOCK]": self.block
}
)()
def post(self):
self.menu(
title="type",
message="Choissisez un type de post",
opt={
"Workshop": self.workshop
}
)(tag="post")
def workshop(self, tag: str):
infos = [
inquirer.List("lab",
message="Selection lab",
choices=EVENT_POSTS_TYPES["lab"],
carousel=True, ),
inquirer.Text("title",
message="Nom de l'évènement"),
inquirer.Text("date",
message="Date (RESPECTEZ LE FORMAT *JJ MMM*, ex: 12 MAR)"),
inquirer.Text("hour",
message="Heure (RESPECTEZ LE FORMAT *HH:MM*)"),
inquirer.Text("location",
message="Localisation (EN UN MOT SI POSSIBLE)"),
]
infos = inquirer.prompt(infos)
infos["tag"] = f"{tag}_workshop"
print(infos)
print(list(infos.values())[:-1])
# img = api_generic.generate_image(list(infos.values()))
img = api_generic.generate_image(infos)
# img.show()
def story(self):
self.menu(
title="type",
message="Choissisez un type de post",
opt={
"Workshop": self.workshop
# "classic":,
# "reminder":,
# "citation":,
# "poll/quiz/question":,
}
)(tag="story")
def description(self):
infos = [
inquirer.Text("description",
message="Donnez simplement un titre pour une description")
]
description = api_generic.generate_text(inquirer.prompt(infos)["description"])
print(description)
def block(self):
infos = [
inquirer.Text("block",
message="Veuillez donner le lien du fichier CSV contenant les events a créer")
]
description = api_generic.generate_text(inquirer.prompt(infos)["block"])
def close(self):
exit(0)
if __name__ == '__main__':
try:
cli = CLI()
except KeyboardInterrupt:
print("\n" + Colors.WARNING + "Arrêt du programme..." + Colors.ENDC)
sys.exit(0)