Compare commits

..

No commits in common. "ef3490b8f556e2f0e7d254060a2e96e0e3e404ef" and "7bda9ca4088f0839c2f6a712f26f739dedb32341" have entirely different histories.

10 changed files with 36 additions and 96 deletions

View File

@ -9,7 +9,3 @@ Doc.: https://python-docs-es.readthedocs.io/es/3.10/library/venv.html
* Python ~ tutorial Jinja templates * Python ~ tutorial Jinja templates
https://realpython.com/primer-on-jinja-templating/ https://realpython.com/primer-on-jinja-templating/
* Control flow - Jinja tpl 's
MUSICA INSTRUMENTAL : Wim Mertens

27
good_messages.py Normal file
View File

@ -0,0 +1,27 @@
# 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)

View File

@ -1,9 +0,0 @@
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

View File

@ -1,9 +0,0 @@
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

View File

@ -1,9 +0,0 @@
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

View File

@ -1,9 +0,0 @@
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

View File

@ -1,9 +0,0 @@
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

9
templates/good.text Normal file
View File

@ -0,0 +1,9 @@
{# 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

View File

@ -1,20 +0,0 @@
{# 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

View File

@ -1,27 +0,0 @@
# 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}")