Upload the program and seed data
This commit is contained in:
commit
daf3d17995
2 changed files with 424 additions and 0 deletions
55
reading-plan.py
Normal file
55
reading-plan.py
Normal file
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/env python3
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
from calendar import month_abbr
|
||||
|
||||
start_year = 2025
|
||||
|
||||
def get_event_date(date_str):
|
||||
parts = date_str.split()
|
||||
if len(parts) != 2:
|
||||
return None
|
||||
month_str, day_str = parts
|
||||
month = list(month_abbr).index(month_str)
|
||||
day = int(day_str)
|
||||
# If the month is September (9) or later, use start_year; otherwise, the next year.
|
||||
year = start_year if month >= 9 else start_year + 1
|
||||
return datetime(year, month, day).date()
|
||||
|
||||
events = []
|
||||
with open('reading_plan.md', 'r') as f:
|
||||
# Read only the lines that begin with a pipe symbol ("|")
|
||||
lines = [line for line in f if line.strip().startswith("|")]
|
||||
if len(lines) < 3:
|
||||
raise Exception("Not enough rows in markdown table")
|
||||
# Skip header and separator lines
|
||||
data_lines = lines[2:]
|
||||
for line in data_lines:
|
||||
cols = [c.strip() for c in line.strip().strip("|").split("|")]
|
||||
if len(cols) < 4:
|
||||
continue
|
||||
date_val = get_event_date(cols[0])
|
||||
if not date_val:
|
||||
continue
|
||||
summary = f"Day {cols[1]} Reading"
|
||||
description = f"Old Testament: {cols[2]}\\nNew Testament: {cols[3]}"
|
||||
events.append((date_val, summary, description))
|
||||
|
||||
with open('reading_plan.ics', 'w') as f:
|
||||
f.write("BEGIN:VCALENDAR\n")
|
||||
f.write("VERSION:2.0\n")
|
||||
f.write("PRODID:-//OSB in one Year//EN\n")
|
||||
for date_val, summary, description in events:
|
||||
f.write("BEGIN:VEVENT\n")
|
||||
uid = str(uuid.uuid4())
|
||||
# Use timezone-aware UTC time for DTSTAMP
|
||||
dtstamp = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ")
|
||||
dtstart = date_val.strftime("%Y%m%d")
|
||||
f.write("UID:" + uid + "\n")
|
||||
f.write("DTSTAMP:" + dtstamp + "\n")
|
||||
f.write("DTSTART;VALUE=DATE:" + dtstart + "\n")
|
||||
f.write("SUMMARY:" + summary + "\n")
|
||||
f.write("DESCRIPTION:" + description + "\n")
|
||||
f.write("END:VEVENT\n")
|
||||
f.write("END:VCALENDAR\n")
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue