diff --git a/export_todoist.py b/export_todoist.py index 4d45a62..1d39e7e 100644 --- a/export_todoist.py +++ b/export_todoist.py @@ -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: diff --git a/requirements.txt b/requirements.txt index 402d659..0e2d2a3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ todoist-api-python Jinja2 requests +markdown diff --git a/todoist_backup_template.html b/todoist_backup_template.html index b9be47a..a89eeaf 100644 --- a/todoist_backup_template.html +++ b/todoist_backup_template.html @@ -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; } @@ -40,11 +41,42 @@
{% for comment in task.comments %}- {{ comment.content }} ({{ comment.posted_at }})
@@ -69,11 +101,55 @@
{% for task in project.completed_tasks %}
- Content: {{ task.content }}{{ task.description | markdown | safe }}
+ {% endif %}
+
+ {% 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(' | ') }}
+
- Attachments:
+ Attachments:
- ID: {{ task.id }} | Due: {{ task.due }} | Priority: {{ task.priority }}
+ {{ task.content | markdown | safe }}
+ {% if task.description %} +
{% if task.attachments %}
{% for att in task.attachments %}- {{ att.file_name or att.local_file }}