#!/usr/bin/env python3 """ # Script ob-file-tasks ## Metadata **Kind**: #obsidian/ob-script **Language**: #bash **Parent**:: [[♯ Todoist]], [[Obsidian Chore Scripts]], [[♯ IFTTT]], [[Executable Markdown File]] ## Synopsis I save completed tasks in Todoist into Dropbox via IFTTT. This script adds the completed tasks to my daily journal files. ## Script ```python # """ import os import glob import re from datetime import datetime, timedelta def _date(date_str): return datetime.strptime(date_str, "%Y-%m-%d").strftime("%a, %b %d, %Y") def _tomorrow(date_str): return (datetime.strptime(date_str, "%Y-%m-%d") + timedelta(days=1)).strftime( "%Y-%m-%d" ) def _yesterday(date_str): return (datetime.strptime(date_str, "%Y-%m-%d") - timedelta(days=1)).strftime( "%Y-%m-%d" ) def file_tasks(): for file in glob.glob("robot/Robot Inbox/Completed Tasks on *.txt"): print(f"File {file}") date = os.path.splitext(os.path.basename(file))[0].split()[-1] journal_file = f"journal/Journal {date}.md" if not os.path.exists(journal_file): with open(journal_file, "w", newline="\n") as f: f.write(f"# Journal on {_date(date)}\n\n") f.write("## Metadata\n\n") f.write(f"**Date**:: [[{date}]]\n") f.write(f"**Next**:: [[Journal {_tomorrow(date)}]]\n") f.write(f"**Prev**:: [[Journal {_yesterday(date)}]]\n") f.write("**Kind**:: #journal\n") with open(journal_file, "a", newline="\n") as f: f.write("\n") f.write("## Completed Tasks\n") f.write("\n") with open(file, "r") as task_file: content = task_file.read() content = re.sub(r"\[\[♯ ([^]]+)\]\]", r"(j:: [[♯ \1]])", content) f.write(content) os.remove(file) if __name__ == "__main__": file_tasks() """ # vim: ft=python ``` """