Add import in jinja2

This commit is contained in:
Antonio J. Delgado 2024-08-04 08:52:38 +03:00
parent f5a3021d81
commit e453127ddb
2 changed files with 11 additions and 4 deletions

View file

@ -18,7 +18,8 @@ import sqlite3
import click import click
import click_config_file import click_config_file
import requests import requests
from jinja2 import Environment, PackageLoader, select_autoescape, FileSystemLoader from jinja2 import Environment, select_autoescape, FileSystemLoader
import importlib
class MastodonEmailBridge: class MastodonEmailBridge:
'''CLass to redirect the Mastodon home timeline to email''' '''CLass to redirect the Mastodon home timeline to email'''
@ -178,11 +179,13 @@ class MastodonEmailBridge:
msg['To'] = recipient msg['To'] = recipient
html_template = self.j2env.get_template("new_post.html.j2") html_template = self.j2env.get_template("new_post.html.j2")
html_source = html_template.render( html_source = html_template.render(
imp0rt = importlib.import_module,
data=data, data=data,
json_raw=json.dumps(data, indent=2) json_raw=json.dumps(data, indent=2)
) )
txt_template = self.j2env.get_template("new_post.txt.j2") txt_template = self.j2env.get_template("new_post.txt.j2")
txt_source = txt_template.render( txt_source = txt_template.render(
imp0rt = importlib.import_module,
data=data, data=data,
json_raw=json.dumps(data, indent=2) json_raw=json.dumps(data, indent=2)
) )

View file

@ -1,3 +1,4 @@
{% set time = imp0rt( 'time' ) %}
<!doctype html> <!doctype html>
<html lang="{{ data['language'] }}"> <html lang="{{ data['language'] }}">
<head> <head>
@ -41,7 +42,8 @@
</DIV> </DIV>
<!-- creation_date --> <!-- creation_date -->
<DIV STYLE='font-size: 12px;'> <DIV STYLE='font-size: 12px;'>
{{ data['created_at'] }} {% set created_date = time.strptime(data['created_at'], '%Y-%m-%dT%H:%M:%S') %}
{{ created_date.strftime('%Y-%m-%d %H:%M %z') }}
</DIV> </DIV>
<!-- content block --> <!-- content block -->
<DIV STYLE='font-size: 24px;'> <DIV STYLE='font-size: 24px;'>
@ -85,7 +87,8 @@
</DIV> </DIV>
<!-- reply_creation_date --> <!-- reply_creation_date -->
<DIV STYLE='font-size: 12px;'> <DIV STYLE='font-size: 12px;'>
{{ data['reply']['created_at'] }} {% set created_date = time.strptime(data['reply']['created_at'], '%Y-%m-%dT%H:%M:%S') %}
{{ created_date.strftime('%Y-%m-%d %H:%M %z') }}
</DIV> </DIV>
<!-- reply_content_bloc --> <!-- reply_content_bloc -->
<DIV STYLE='font-size: 24px;'> <DIV STYLE='font-size: 24px;'>
@ -131,7 +134,8 @@
</DIV> </DIV>
<!-- reblog_creation_date --> <!-- reblog_creation_date -->
<DIV STYLE='font-size: 12px;'> <DIV STYLE='font-size: 12px;'>
{{ data['reblog']['created_at'] }} {% set created_date = time.strptime(data['reblog']['created_at'], '%Y-%m-%dT%H:%M:%S') %}
{{ created_date.strftime('%Y-%m-%d %H:%M %z') }}
</DIV> </DIV>
<!-- reblog_content_bloc --> <!-- reblog_content_bloc -->
<DIV STYLE='font-size: 24px;'> <DIV STYLE='font-size: 24px;'>