import xml.etree.ElementTree as ET
import datetime
# Function to generate the outline for a given week
def generate_weekly_opml(week_num, year=2025):
# Start of the week (Sunday)
start_date = datetime.date(year, 1, 1) + datetime.timedelta(weeks=week_num-1)
# Adjust to get the Sunday of the week (since Python's datetime module uses Monday as the start of the week)
start_date = start_date - datetime.timedelta(days=start_date.weekday() + 1)
# monday_date = start_date + datetime.timedelta(days=1)
# Create the root element for the week outline with Sunday date as a note
# week_outline = ET.Element("outline", text=f"2025 Week {week_num}", _note=f"")
week_outline = ET.Element("outline", text=f"2025 Week {week_num}")
# ET.SubElement(week_outline, "outline")
# Loop through the days of the week (Sunday to Saturday)
for i in range(7):
day_date = start_date + datetime.timedelta(days=i)
weekday = day_date.strftime('%A')
# Create the day outline with a link for tasks
day_outline = ET.SubElement(
week_outline,
"outline",
text=f"{weekday}",
_note=f""
)
# Example of activities (these can be customized)
if weekday in ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']:
outline = ET.SubElement(day_outline, "outline", text="")
return week_outline
# Function to return a color based on the weekday (for styling)
def get_color(weekday):
colors = {
"Sunday": "purple",
"Monday": "red",
"Tuesday": "teal",
"Wednesday": "pink",
"Thursday": "green",
"Friday": "yellow",
"Saturday": "sky"
}
return colors.get(weekday, "gray")
# Function to create OPML for all weeks in 2025 and the first week of 2026
def create_opml_for_year_and_first_week_2026():
root_opml = ET.Element("opml", version="2.0")
head = ET.SubElement(root_opml, "head")
owner_email = ET.SubElement(head, "ownerEmail")
owner_email.text = "contact@gregoryleeman.com"
body = ET.SubElement(root_opml, "body")
# Generate OPML for each week of 2025
for week_num in range(1, 53): # There are 52 weeks in 2025
week_opml = generate_weekly_opml(week_num)
body.append(week_opml)
# Now, handle the first week of 2026
week_2026_opml = generate_weekly_opml(1, year=2026)
body.append(week_2026_opml)
# Generate the final tree
tree = ET.ElementTree(root_opml)
return tree
# Create the OPML file
def save_opml_to_file(filename="diary.opml"):
tree = create_opml_for_year_and_first_week_2026()
tree.write(filename, encoding="utf-8", xml_declaration=True)
# Call the function to create the OPML
save_opml_to_file()