You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.6 KiB
67 lines
2.6 KiB
import xml.etree.ElementTree as ET
|
|
import datetime
|
|
|
|
def ordinal(n):
|
|
if 11 <= n % 100 <= 13:
|
|
suffix = 'th'
|
|
else:
|
|
suffix = {1: 'st', 2: 'nd', 3: 'rd'}.get(n % 10, 'th')
|
|
return str(n) + suffix
|
|
|
|
def generate_weekly_opml(week_num, year=2025):
|
|
start_date = datetime.date(year, 1, 1) + datetime.timedelta(weeks=week_num-1)
|
|
start_date = start_date - datetime.timedelta(days=start_date.weekday())
|
|
# start_date = start_date - datetime.timedelta(days=start_date.weekday() + 1)
|
|
day_date = start_date
|
|
weekday = day_date.strftime('%A')
|
|
week_outline = ET.Element(
|
|
"outline",
|
|
text=f"2025 Week {week_num}",
|
|
_note=f"<time startYear='2025' startMonth='{day_date.month}' startDay='{day_date.day}'> {weekday[:3]}, {day_date.strftime('%b')} {day_date.day}, 2025</time>"
|
|
)
|
|
empty = ET.SubElement(week_outline, "outline", text="")
|
|
for i in range(7):
|
|
day_date = start_date + datetime.timedelta(days=i)
|
|
weekday = day_date.strftime('%A')
|
|
day_outline = ET.SubElement(
|
|
week_outline,
|
|
"outline",
|
|
text=f"<b><span class='colored c-{get_color(weekday)}'>{weekday} {ordinal(day_date.day)} {day_date.strftime('%b')}</span></b>",
|
|
_note=f"<time startYear='2025' startMonth='{day_date.month}' startDay='{day_date.day}'> {weekday[:3]}, {day_date.strftime('%b')} {day_date.day}, 2025</time>"
|
|
)
|
|
if weekday in ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']:
|
|
outline = ET.SubElement(day_outline, "outline", text="")
|
|
|
|
return week_outline
|
|
|
|
def get_color(weekday):
|
|
colors = {
|
|
"Sunday": "purple",
|
|
"Monday": "red",
|
|
"Tuesday": "teal",
|
|
"Wednesday": "pink",
|
|
"Thursday": "green",
|
|
"Friday": "yellow",
|
|
"Saturday": "sky"
|
|
}
|
|
return colors.get(weekday, "gray")
|
|
|
|
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 = "[email protected]"
|
|
body = ET.SubElement(root_opml, "body")
|
|
for week_num in range(1, 53):
|
|
week_opml = generate_weekly_opml(week_num)
|
|
body.append(week_opml)
|
|
week_2026_opml = generate_weekly_opml(1, year=2026)
|
|
body.append(week_2026_opml)
|
|
tree = ET.ElementTree(root_opml)
|
|
return tree
|
|
|
|
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)
|
|
|
|
save_opml_to_file()
|
|
|