#!/usr/bin/env python3 """ # Script ob-file-picks ## Metadata **Kind**: #obsidian/ob-script **Language**: #python **Parent**:: [[Obsidian Chore Scripts]], [[♯ IFTTT]], [[Executable Markdown File]] ## Synopsis I save all tweets with tag #pick into Dropbox via IFTTT. This script adds the picks 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_picks(): for file in glob.glob("robot/Robot Inbox/Picks 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("## Picks\n") f.write("\n") with open(file, "r") as picks_file: content = picks_file.read() f.write(content) os.remove(file) if __name__ == "__main__": file_picks() """ # vim: ft=python ``` """