HTML output tweaks

This commit is contained in:
2025-10-18 10:38:43 -04:00
parent 171c5df068
commit 31455f075e
3 changed files with 91 additions and 8 deletions

View File

@ -162,6 +162,12 @@ def main():
loader=FileSystemLoader(os.path.dirname(__file__)),
autoescape=select_autoescape(['html', 'xml'])
)
# Add markdown filter
try:
import markdown
env.filters['markdown'] = lambda text: markdown.markdown(text or "")
except ImportError:
env.filters['markdown'] = lambda text: text or ""
template = env.get_template("todoist_backup_template.html")
html_filename = f"Todoist-Actual-Backup-{today}.html"
with open(html_filename, "w", encoding="utf-8") as f:

View File

@ -1,3 +1,4 @@
todoist-api-python
Jinja2
requests
markdown

View File

@ -13,7 +13,8 @@
.completed { color: #888; }
.attachments { margin: 0.5em 0 0.5em 1em; }
.comments { margin: 0.5em 0 0.5em 1em; font-size: 0.95em; color: #444; }
.field { font-weight: bold; }
.task-name { font-weight: bold; }
.field-label { font-style: italic; }
a.attachment-link { color: #2d72d9; text-decoration: underline; }
.meta { color: #666; font-size: 0.95em; }
</style>
@ -40,11 +41,42 @@
<div class="task-list">
{% for task in project.tasks %}
<div class="task">
<span class="field">Content:</span> {{ task.content }}<br>
<span class="meta">ID: {{ task.id }} | Due: {{ task.due }} | Priority: {{ task.priority }}</span><br>
<span class="taskname">{{ task.content | markdown | safe }}</span><br>
{% if task.description %}
<div class="taskdesc">{{ task.description | markdown | safe }}</div>
{% endif %}
<span class="meta">
{% set meta_fields = [] %}
{% if task.id is not none %}
{% set _ = meta_fields.append('ID: ' ~ task.id) %}
{% endif %}
{% if task.due and task.due.date %}
{% set due_dt = task.due.date %}
{% if due_dt.__class__.__name__ == 'datetime' or due_dt.__class__.__name__ == 'date' %}
{% set due_fmt = due_dt.strftime('%Y-%m-%d') %}
{% else %}
{% set due_str = due_dt|string %}
{% if 'T' in due_str %}
{% set due_fmt = due_str[:10] %}
{% else %}
{% set due_fmt = due_str %}
{% endif %}
{% endif %}
{% set _ = meta_fields.append('Due: ' ~ due_fmt) %}
{% endif %}
{% if task.due and task.due.is_recurring %}
{% if task.due.string %}
{% set _ = meta_fields.append('Recurring: ' ~ task.due.string) %}
{% endif %}
{% endif %}
{% if task.priority is not none %}
{% set _ = meta_fields.append('Priority: ' ~ task.priority) %}
{% endif %}
{{ meta_fields|join(' | ') }}
</span><br>
{% if task.attachments %}
<div class="attachments">
<span class="field">Attachments:</span>
<span class="field-name">Attachments:</span>
<ul>
{% for att in task.attachments %}
<li><a class="attachment-link" href="{{ att.local_file }}" download>{{ att.file_name or att.local_file }}</a></li>
@ -54,7 +86,7 @@
{% endif %}
{% if task.comments %}
<div class="comments">
<span class="field">Comments:</span>
<span class="field-name">Comments:</span>
<ul>
{% for comment in task.comments %}
<li>{{ comment.content }} <span class="meta">({{ comment.posted_at }})</span></li>
@ -69,11 +101,55 @@
<div class="task-list">
{% for task in project.completed_tasks %}
<div class="task completed">
<span class="field">Content:</span> {{ task.content }}<br>
<span class="meta">ID: {{ task.id }} | Due: {{ task.due }} | Priority: {{ task.priority }}</span><br>
<span class="task-name">{{ task.content | markdown | safe }}</span><br>
{% if task.description %}
<div class="taskdesc">{{ task.description | markdown | safe }}</div>
{% endif %}
<span class="meta">
{% set meta_fields = [] %}
{% if task.id is not none %}
{% set _ = meta_fields.append('ID: ' ~ task.id) %}
{% endif %}
{% if task.due and task.due.date %}
{% set due_dt = task.due.date %}
{% if due_dt.__class__.__name__ == 'datetime' or due_dt.__class__.__name__ == 'date' %}
{% set due_fmt = due_dt.strftime('%Y-%m-%d %H:%M') if due_dt.__class__.__name__ == 'datetime' else due_dt.strftime('%Y-%m-%d 00:00') %}
{% else %}
{% set due_str = due_dt|string %}
{% if 'T' in due_str %}
{% set due_fmt = due_str[:16].replace('T', ' ') %}
{% else %}
{% set due_fmt = due_str %}
{% endif %}
{% endif %}
{% set _ = meta_fields.append('Due: ' ~ due_fmt) %}
{% endif %}
{% if task.due and task.due.is_recurring %}
{% if task.due.string %}
{% set _ = meta_fields.append('Recurring: ' ~ task.due.string) %}
{% endif %}
{% endif %}
{% if task.priority is not none %}
{% set _ = meta_fields.append('Priority: ' ~ task.priority) %}
{% endif %}
{% if task.completed_at %}
{% if task.completed_at.__class__.__name__ == 'datetime' or task.completed_at.__class__.__name__ == 'date' %}
{% set completed_fmt = task.completed_at.strftime('%Y-%m-%d') %}
{% else %}
{% set completed_str = task.completed_at|string %}
{% if 'T' in completed_str %}
{% set completed_fmt = completed_str[:10] %}
{% else %}
{% set completed_fmt = completed_str %}
{% endif %}
{% endif %}
{% set _ = meta_fields.append('Completed: ' ~ completed_fmt) %}
{% endif %}
{{ meta_fields|join(' | ') }}
</span><br>
{% if task.attachments %}
<div class="attachments">
<span class="field">Attachments:</span>
<span class="field-name">Attachments:</span>
<ul>
{% for att in task.attachments %}
<li><a class="attachment-link" href="{{ att.local_file }}" download>{{ att.file_name or att.local_file }}</a></li>