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

View file

@ -1,3 +1,4 @@
{% set time = imp0rt( 'time' ) %}
<!doctype html>
<html lang="{{ data['language'] }}">
<head>
@ -41,7 +42,8 @@
</DIV>
<!-- creation_date -->
<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>
<!-- content block -->
<DIV STYLE='font-size: 24px;'>
@ -85,7 +87,8 @@
</DIV>
<!-- reply_creation_date -->
<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>
<!-- reply_content_bloc -->
<DIV STYLE='font-size: 24px;'>
@ -131,7 +134,8 @@
</DIV>
<!-- reblog_creation_date -->
<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>
<!-- reblog_content_bloc -->
<DIV STYLE='font-size: 24px;'>