Refactor OrgData class with docstrings for readability and functionality
This commit is contained in:
parent
ef42bc6b8c
commit
587dd9bf89
34
org.py
34
org.py
@ -1,3 +1,5 @@
|
||||
"""Org module."""
|
||||
|
||||
import locale
|
||||
from datetime import datetime
|
||||
|
||||
@ -8,8 +10,19 @@ from settings import ORG_CAPTURE_FILENAME, ORG_LINKS_FILENAME, ORG_PLAN_FILENAME
|
||||
locale.setlocale(locale.LC_ALL, "es_ES.utf8")
|
||||
|
||||
|
||||
class OrgData():
|
||||
class OrgData:
|
||||
"""Manage org-mode files for TODO items, plans, and links.
|
||||
|
||||
Provides functionality to read and write org-mode formatted data, including
|
||||
TODOs, daily plans, and links. Handles file operations and data formatting.
|
||||
"""
|
||||
|
||||
def _generate_today(self):
|
||||
"""Generate a formatted timestamp for today's date.
|
||||
|
||||
Returns:
|
||||
str: Formatted string with date, day, and time (YYYY-MM-DD day HH:MM)
|
||||
"""
|
||||
today = datetime.today()
|
||||
today_ymd = today.strftime("%Y-%m-%d")
|
||||
today_day = today.strftime("%a").lower()
|
||||
@ -17,7 +30,14 @@ class OrgData():
|
||||
return f"{today_ymd} {today_day} {today_hour}"
|
||||
|
||||
def add_new_todo(self, keyword: str, description: str, outcome: str, extra: str) -> None:
|
||||
"""Add a new TODO item to the capture file.
|
||||
|
||||
Args:
|
||||
keyword: Category of TODO (e.g., 'TODO', 'REPEAT', 'NEXT')
|
||||
description: Title/description of the task
|
||||
outcome: Desired outcome or objective
|
||||
extra: Additional notes or context
|
||||
"""
|
||||
today = self._generate_today()
|
||||
|
||||
todo_template = f"""
|
||||
@ -34,6 +54,14 @@ class OrgData():
|
||||
capture_file.write(todo_template)
|
||||
|
||||
def list_plan(self, filename: str) -> str:
|
||||
"""Get and format the daily plan from an org file.
|
||||
|
||||
Args:
|
||||
filename: Type of plan to retrieve ('free' or 'work')
|
||||
|
||||
Returns:
|
||||
str: Formatted plan with checkboxes converted to emoji markers
|
||||
"""
|
||||
with open(ORG_PLAN_FILENAME.replace("{filename}", filename), "r") as agenda:
|
||||
plan = agenda.read()
|
||||
|
||||
@ -42,6 +70,10 @@ class OrgData():
|
||||
return plan[-1].get_body().replace("[X]", "✅").replace("[ ]", "❌")
|
||||
|
||||
def add_new_link(self, link: str) -> None:
|
||||
"""Add a new link to the links file.
|
||||
|
||||
Args:
|
||||
link: URL to be saved
|
||||
"""
|
||||
with open(ORG_LINKS_FILENAME, "a") as capture_file:
|
||||
capture_file.write(link)
|
||||
|
@ -1,3 +1,5 @@
|
||||
"""Settings module."""
|
||||
|
||||
import os
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
Loading…
x
Reference in New Issue
Block a user