Compare commits
2 Commits
7bda9ca408
...
ef3490b8f5
Author | SHA1 | Date |
---|---|---|
fenix | ef3490b8f5 | |
fenix | ee87a0715a |
|
@ -9,3 +9,7 @@ Doc.: https://python-docs-es.readthedocs.io/es/3.10/library/venv.html
|
|||
|
||||
* Python ~ tutorial Jinja templates
|
||||
https://realpython.com/primer-on-jinja-templating/
|
||||
|
||||
* Control flow - Jinja tpl 's
|
||||
|
||||
MUSICA INSTRUMENTAL : Wim Mertens
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
# good_messages.py
|
||||
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
MAX_SCORE = 100
|
||||
TEST_NAME = "Python Challenge"
|
||||
|
||||
students = [
|
||||
{"name" : "Willow", "score":100},
|
||||
{"name" : "Cordelia", "score":85},
|
||||
{"name" : "Oz", "score":95},
|
||||
]
|
||||
|
||||
env = Environment(loader=FileSystemLoader("templates/"))
|
||||
template = env.get_template("good.txt")
|
||||
|
||||
for student in students:
|
||||
name = student["name"]
|
||||
filename = f"output/message_{name.lower()}.txt"
|
||||
content = template.render(
|
||||
student,
|
||||
max_score=MAX_SCORE,
|
||||
test_name=TEST_NAME
|
||||
)
|
||||
with open(filename, mode="w", encoding="utf-8") as output:
|
||||
output.write(content)
|
||||
print("... wrote", filename)
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
HOLA! Frieda,
|
||||
|
||||
Estoy happy to inform you that you did very well on today's Python Challenge.
|
||||
HAs alcanzado esta puntuacion : 92 de { max_score }} PUNTOS !
|
||||
|
||||
see you tomorrow, nos vemos :-)
|
||||
|
||||
Mr. JokerPy
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
HOLA! Fritz,
|
||||
|
||||
Estoy happy to inform you that you did very well on today's Python Challenge.
|
||||
HAs alcanzado esta puntuacion : 40 de { max_score }} PUNTOS !
|
||||
|
||||
see you tomorrow, nos vemos :-)
|
||||
|
||||
Mr. JokerPy
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
HOLA! Gergeley,
|
||||
|
||||
Estoy happy to inform you that you did very well on today's Python Challenge.
|
||||
HAs alcanzado esta puntuacion : 87 de { max_score }} PUNTOS !
|
||||
|
||||
see you tomorrow, nos vemos :-)
|
||||
|
||||
Mr. JokerPy
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
HOLA! Sandrine,
|
||||
|
||||
Estoy happy to inform you that you did very well on today's Python Challenge.
|
||||
HAs alcanzado esta puntuacion : 100 de { max_score }} PUNTOS !
|
||||
|
||||
see you tomorrow, nos vemos :-)
|
||||
|
||||
Mr. JokerPy
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
HOLA! Sirius,
|
||||
|
||||
Estoy happy to inform you that you did very well on today's Python Challenge.
|
||||
HAs alcanzado esta puntuacion : 75 de { max_score }} PUNTOS !
|
||||
|
||||
see you tomorrow, nos vemos :-)
|
||||
|
||||
Mr. JokerPy
|
|
@ -1,9 +0,0 @@
|
|||
{# templates/good.txt #}
|
||||
Hello {{ name }},
|
||||
|
||||
I'm happy to inform you that you did very well on today's {{ test_name }}.
|
||||
You achieved {{ score }} out of { max_score }} points !
|
||||
|
||||
see you tomorrow, nos vemos :-)
|
||||
|
||||
Ms. Hypyatia
|
|
@ -0,0 +1,20 @@
|
|||
{# templates/message.txt #}
|
||||
HOLA! {{ name }},
|
||||
|
||||
{% if score > 80 %}
|
||||
|
||||
( Acá Informamos tan sólo en caso de una cierta puntuación, por encima de un umbral )
|
||||
|
||||
Estoy happy to inform you that you did very well on today's {{ test_name }}.
|
||||
HAs alcanzado esta puntuacion : {{ score }} de { max_score }} PUNTOS ! ;-)
|
||||
|
||||
{% else %}
|
||||
|
||||
Vaya! Siento informarte de que tu puntuacuón : {{ score }} es más que mejorable ... {{ test_name }} :-|
|
||||
|
||||
{% endif %}
|
||||
|
||||
|
||||
see you tomorrow, nos vemos :-)
|
||||
|
||||
Mr. JokerPy
|
|
@ -0,0 +1,27 @@
|
|||
# write_messages.py
|
||||
|
||||
from jinja2 import Environment, FileSystemLoader
|
||||
|
||||
max_score = 100
|
||||
test_name = "Python Challenge"
|
||||
students = [
|
||||
{"name": "Sandrine", "score": 100},
|
||||
{"name": "Gergeley", "score": 87},
|
||||
{"name": "Frieda", "score": 92},
|
||||
{"name": "Fritz", "score": 40},
|
||||
{"name": "Sirius", "score": 75},
|
||||
]
|
||||
|
||||
environment = Environment(loader=FileSystemLoader("templates/"))
|
||||
template = environment.get_template("message.txt")
|
||||
|
||||
for student in students:
|
||||
filename = f"message_{student['name'].lower()}.txt"
|
||||
content = template.render(
|
||||
student,
|
||||
max_score=max_score,
|
||||
test_name=test_name
|
||||
)
|
||||
with open(filename, mode="w", encoding="utf-8") as message:
|
||||
message.write(content)
|
||||
print(f"... wrote {filename}")
|
Loading…
Reference in New Issue