Compare commits

...
29 Commits
Author SHA1 Message Date
fwarren 12f096c56d use day occurance counter instead of week counter 2026-01-02 13:59:52 -05:00
fwarren 4e571b1b41 Updated requirments for python 3.12+ 2026-01-02 13:47:50 -05:00
Fredrick W. Warren 180d29f158 updated events January 2026 2026-01-02 10:38:02 -08:00
fwarren 44a333f6a0 added monday demtia meeting, removed wed youth morning 2025-10-19 10:58:19 -06:00
fwarren b601ef0c67 added --months -m to accept a month or range of months 2025-09-07 10:23:39 -06:00
fwarren 5c4060cff3 newline fix for window 2025-09-07 05:04:16 -06:00
fwarren bfb38e6a00 added level up and youth group services 2025-09-06 19:03:29 -06:00
fwarren 1e0fbccd07 added Sunday PM Services 2025-03-15 09:02:28 -06:00
fwarren 944d34e3a5 changed main docstring 2024-12-29 10:41:28 -07:00
fwarren 2ecb916a2f pass filename to writer, default calendar.csv 2024-12-29 10:20:36 -07:00
fwarren 9707095cc1 repalced global MONTHS with local months 2024-12-29 10:01:32 -07:00
fwarren 1c480360df refactor and add cli options
- refactor the creation of MONTHS into a definition
- refactor the creation of event_list from EVENTS into a definition
- both of these are initalized in main()
- added option --debug/-d to enable debug printing, default = off
- added option --year/-y for year, default = current year
2024-12-29 09:56:29 -07:00
fwarren bf5234aa6e YEAR is now a default command line option in main 2024-12-29 09:53:31 -07:00
fwarren 71222aa59c convert newlines in descrption field to \n 2024-12-29 08:50:37 -07:00
fwarren 0b97ad1e49 added actuall event creation 2024-12-29 08:23:16 -07:00
fwarren 6b39ed588d delete junk file 3q 2024-12-29 07:48:21 -07:00
fwarren bfa5d994a9 corrected spelling of Coffee 2024-12-29 07:46:23 -07:00
fwarren 889022c84c added processing events by day 2024-12-29 07:46:00 -07:00
fwarren f786cceed1 updated debug print 2024-12-29 07:41:15 -07:00
fwarren a77019638d setup debug printing 2024-12-29 07:30:41 -07:00
fwarren 037981040a moved processing into months and month 2024-12-29 07:20:53 -07:00
fwarren 284885c221 moved processing from main to process_year 2024-12-29 07:05:07 -07:00
fwarren ea9d02a03a rework main and enabled Click 2024-12-29 06:47:04 -07:00
fwarren 84674d8ae5 renamed processed EVENTS to monthly_events 2024-12-29 06:46:28 -07:00
fwarren a8cfff3dfe enabled all includes 2024-12-29 06:44:43 -07:00
fwarren caa70cc69b changed format of events 2024-12-28 20:18:36 -07:00
fwarren 0e8637edff documented EVENT_LIST 2024-12-28 10:36:08 -07:00
fwarren fe5b7eaae0 reformatted due to adding week 6 to Tuesday 2024-12-28 10:34:26 -07:00
fwarren a85fa66954 Moved Event defintions to new file 2024-12-27 22:01:57 -07:00
3 changed files with 144 additions and 348 deletions

No files matched your search

+3
View File
@@ -1 +1,4 @@
Program to generate a csv for importing calendar events Program to generate a csv for importing calendar events
If using python 3.12 + need to `pip install --upgrade setuptools`
Executable
+34
View File
@@ -0,0 +1,34 @@
#!/usr/bin/env python
"""
CHURCH CALENDAR EVENTS LIST
Wednesday to Sunday have 5 weeks
Monday and Tuesday have 6 weeks
category must match the ones in WordPress
"""
from calendar import SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
# level up first monday 6:00-7:30 Youth Group wednesday 6:00
EVENT_LIST = ( # ------------- ----------------
# day weeks start end venue category name description
(SUNDAY, [1 ], 10, 00, 12, 00, "Main Campus", "Sunday Service", "Sunday Service 10:00am", "Prayer Room open from 8:30 AM to 9:30 AM. Worship Service starts at 10:00 AM. First Sunday of the month is Missions Sunday"),
(SUNDAY, [2 ], 10, 00, 12, 00, "Main Campus", "Sunday Service", "Sunday Service 10:00am", "Prayer Room open from 8:30 AM to 9:30 AM. Worship Service starts at 10:00 AM. Second Sunday of the month is Baptism Sunday"),
(SUNDAY, [3 ], 10, 00, 12, 00, "Main Campus", "Sunday Service", "Sunday Service 10:00am", "Prayer Room open from 8:30 AM to 9:30 AM. Worship Service starts at 10:00 AM. Third Sunday of the month is Communion Sunday"),
(SUNDAY, [4 ], 10, 00, 12, 00, "Main Campus", "Sunday Service", "Sunday Service 10:00am", "Prayer Room open from 8:30 AM to 9:30 AM. Worship Service starts at 10:00 AM. Fourth Sunday of the month is Coins for Kids Sunday"),
(SUNDAY, [5 ], 10, 00, 12, 00, "Main Campus", "Sunday Service", "Sunday Service 10:00am", "Prayer Room open from 8:30 AM to 9:30 AM. Worship Service starts at 10:00 AM. Fifth Sunday of the month is Potluck Sunday"),
(SUNDAY, [1, 2, 3, 4, 5, 6], 18, 00, 19, 00, "Main Campus", "Sunday Service", "Sunday Eventing Service", ""),
(MONDAY, [1 ], 18, 00, 19, 30, "Main Campus", "Woman's Meeting", "Level Up 6:00pm", ""),
(MONDAY, [2 ], 18, 00, 19, 30, "Main Campus", "Woman's Meeting", "Ladies Night Out 6:00pm", "Come join us for a time of fun and fellowship\n\nBabysitting will be provided."),
(MONDAY, [4 ], 16, 00, 17, 00, "Main Campus", "Dementia Support", "Dementia Support Group 4:00pm", "Dementia and Alzheimer's Support Group"),
(TUESDAY, [1, 2, 3, 4, 5, 6], 18, 00, 20, 00, "Main Campus", "Grief Share", "Grief Share 6:00pm", ""),
(WEDNESDAY, [1, 2, 3, 4, 5 ], 18, 00, 20, 00, "Main Campus", "Youth Group", "Youth Group 6:00pm", ""),
(WEDNESDAY, [3 ], 11, 30, 14, 00, "Main Campus", "Silver Seekers", "Silver Seekers 11:30am", "For those 60 and up. Join us for some food and some exciting events and fellowship."),
(WEDNESDAY, [1, 2, 3, 4, 5 ], 18, 00, 20, 00, "Main Campus", "Mid Week Service", "Mid Week Service 6:00pm", ""),
(THURSDAY, [1, 2, 3, 4, 5 ], 10, 00, 12, 00, "Main Campus", "Woman's Meeting", "Woman's Meeting 10:00am", "Woman 2 Woman Bible Study"),
(FRIDAY, [1, 2, 3, 4 ], 18, 30, 20, 30, "Main Campus", "Men's Meeting", "For Men Only 6:30pm", "Men's Bible Study"),
(FRIDAY, [5 ], 19, 00, 21, 00, "Main Campus", "Movie Night", "Family Movie Night 7:00pm", "To Be Announced"),
(SATURDAY, [1 ], 9, 00, 12, 00, "Main Campus", "Cleanup", "Church Cleanup 9:00am", "Working hearts and hands for God's House"),
(SATURDAY, [2 ], 8, 00, 10, 00, "Main Campus", "Men's Meeting", "Men's Breakfast 8:00am", ""),
# (--------, [- ], 18, 00, 20, 00, "Main Campus", "Youth Group", "South County Youth Group 6:00pm", ""),
)
DEBUG = True
+107 -348
View File
@@ -5,18 +5,33 @@ CHURCH CALENDAR CSV GENERATOR
import calendar import calendar
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime from datetime import date, datetime
# from pprint import pprint
import sys import sys
import click import click
from dataclass_csv import DataclassWriter from dataclass_csv import DataclassWriter
from events import EVENT_LIST
def initalize_events(event_list):
""" convert EVENT_LIST into monthly_events """
monthly_events = [[] for _ in range(7)]
for event in event_list:
monthly_events[event[0]].append(event[1:])
return monthly_events
def debug_print(data, condition=True, end="\n"):
"""Conditionally print data."""
if condition:
print(data, end=end)
def initalize_year(year: int) -> dict[int, list[list[int]]]:
months = dict(enumerate
([calendar.monthcalendar(year, month) for month in range(1, 13)],
start=1))
return months
@dataclass @dataclass
class Event(): class Event():
"""Event for CSV export""" """Event for CSV export"""
# pylint: disable=too-many-instance-attributes
event_name: str event_name: str
venue_name: str venue_name: str
organizer_name: str organizer_name: str
@@ -33,12 +48,6 @@ class Event():
show_map: str show_map: str
event_description: str event_description: str
YEAR: int = 2024
MONTHS: dict[int, list[list[int]]]
MONTHS = dict(enumerate([calendar.monthcalendar(YEAR, month) for month in
range(1, 13)], start=1))
def suffix(day: int) -> str: def suffix(day: int) -> str:
"""convert day to suffix""" """convert day to suffix"""
result: str = 'th' result: str = 'th'
@@ -50,22 +59,15 @@ def suffix(day: int) -> str:
result = 'rd' result = 'rd'
return result return result
def create_event(name: str,
def sort_events(events: list[Event]) -> list[Event]: location: str,
"""sort events"""
events = sorted(events, key=lambda k: (k.start_date, k.start_time))
return events
def add_event(events: list[Event],
name: str,
categories: str, categories: str,
description: str, description: str,
start, start,
finish) -> None: finish) -> Event:
"""create event""" """create event object"""
# pylint: disable=too-many-arguments
event = Event(name, event = Event(name,
"Main Campus", location,
"", "",
start.strftime("%Y-%m-%d"), start.strftime("%Y-%m-%d"),
start.strftime("%I:%M %p"), start.strftime("%I:%M %p"),
@@ -79,319 +81,11 @@ def add_event(events: list[Event],
"", "",
"", "",
description) description)
events.append(event) return event
def add_tuesdays(events: list[Event], def write_calendar(events: list[Event], filename) -> None:
year: int,
month: int,
weeks: list[list[int]]) -> None:
"""add Tuesday events to calendar"""
days = [day[1] for day in weeks if day[1]]
add_event(events,
"Grief Share 6:00pm",
"Grief Share",
"",
datetime(year, month, days[0], 19, 00, 00),
datetime(year, month, days[0], 21, 00, 00),
)
add_event(events,
"Grief Share 6:00pm",
"Grief Share",
"",
datetime(year, month, days[1], 19, 00, 00),
datetime(year, month, days[1], 21, 00, 00),
)
add_event(events,
"Grief Share 6:00pm",
"Grief Share",
"",
datetime(year, month, days[2], 19, 00, 00),
datetime(year, month, days[2], 21, 00, 00),
)
add_event(events,
"Grief Share 6:00pm",
"Grief Share",
"",
datetime(year, month, days[3], 19, 00, 00),
datetime(year, month, days[3], 21, 00, 00),
)
if len(days) == 5:
add_event(events,
"Grief Share 6:00pm",
"Grief Share",
"",
datetime(year, month, days[4], 19, 00, 00),
datetime(year, month, days[4], 21, 00, 00),
)
def add_wednesdays(events: list[Event],
year: int,
month: int,
weeks: list[list[int]]) -> None:
"""add Wednesday events to calendar"""
days = [day[2] for day in weeks if day[2]]
add_event(events,
"Mid Week Service 6:00pm",
"Mid Week Service",
"",
datetime(year, month, days[0], 19, 00, 00),
datetime(year, month, days[0], 21, 00, 00),
)
add_event(events,
"Mid Week Service 6:00pm",
"Mid Week Service",
"",
datetime(year, month, days[1], 19, 00, 00),
datetime(year, month, days[1], 21, 00, 00),
)
add_event(events,
"Mid Week Service 6:00pm",
"Mid Week Service",
"",
datetime(year, month, days[2], 19, 00, 00),
datetime(year, month, days[2], 21, 00, 00),
)
add_event(events,
"Mid Week Service 6:00pm",
"Mid Week Service",
"",
datetime(year, month, days[3], 19, 00, 00),
datetime(year, month, days[3], 21, 00, 00),
)
if len(days) == 5:
add_event(events,
"Mid Week Service 6:00pm",
"Mid Week Service",
"",
datetime(year, month, days[4], 19, 00, 00),
datetime(year, month, days[4], 21, 00, 00),
)
def add_thursdays(events: list[Event],
year: int,
month: int,
days: list[list[int]]) -> None:
"""add Thursday events to calendar"""
days = [day[3] for day in days if day[3]]
add_event(events,
"Woman’s Meeting 10:00am",
"Woman’s Meeting",
"Woman 2 Woman Bible Study",
datetime(year, month, days[0], 10, 00, 00),
datetime(year, month, days[0], 11, 00, 00),
)
add_event(events,
"Woman’s Meeting 10:00am",
"Woman’s Meeting",
"Woman 2 Woman Bible Study",
datetime(year, month, days[1], 10, 00, 00),
datetime(year, month, days[1], 11, 00, 00),
)
add_event(events,
"Woman’s Meeting 10:00am",
"Woman’s Meeting",
"Woman 2 Woman Bible Study",
datetime(year, month, days[2], 10, 00, 00),
datetime(year, month, days[2], 11, 00, 00),
)
add_event(events,
"Woman’s Meeting 10:00am",
"Woman’s Meeting",
"Woman 2 Woman Bible Study",
datetime(year, month, days[3], 10, 00, 00),
datetime(year, month, days[3], 11, 00, 00),
)
if len(days) == 5:
add_event(events,
"Woman’s Meeting 10:00am",
"Woman’s Meeting",
"Woman 2 Woman Bible Study",
datetime(year, month, days[4], 10, 00, 00),
datetime(year, month, days[4], 11, 00, 00),
)
def add_fridays(events: list[Event],
year: int,
month: int,
days: list[list[int]]) -> None:
"""add Friday events to calendar"""
days = [day[4] for day in days if day[4]]
add_event(events,
"For Men Only 6:30pm",
"Men’s Meeting",
"Mens Bible Stude",
datetime(year, month, days[0], 18, 30, 00),
datetime(year, month, days[0], 19, 30, 00),
)
add_event(events,
"For Men Only 6:30pm",
"Men’s Meeting",
"Mens Bible Stude",
datetime(year, month, days[1], 18, 30, 00),
datetime(year, month, days[1], 19, 30, 00),
)
add_event(events,
"For Men Only 6:30pm",
"Men’s Meeting",
"Mens Bible Stude",
datetime(year, month, days[2], 18, 30, 00),
datetime(year, month, days[2], 19, 30, 00),
)
add_event(events,
"For Men Only 6:30pm",
"Men’s Meeting",
"Mens Bible Stude",
datetime(year, month, days[3], 18, 30, 00),
datetime(year, month, days[3], 19, 30, 00),
)
if len(days) == 5:
add_event(events,
"Family Movie Night 7:00pm",
"Movie Night",
"Movie to be announced",
datetime(year, month, days[4], 19, 00, 00),
datetime(year, month, days[4], 21, 00, 00),
)
def add_saturdays(events: list[Event],
year: int,
month: int,
weeks: list[list[int]]) -> None:
"""add Saturday events to calendar"""
days = [day[5] for day in weeks if day[5]]
add_event(events,
"Men's Breakfast 8:00am",
"Men's Meeting",
"",
datetime(year, month, days[1], 8, 00, 00),
datetime(year, month, days[1], 10, 00, 00),
)
def add_sundays(events: list[Event],
year: int,
month: int,
weeks: list[list[int]]) -> None:
"""add Sunday events to calendar"""
days = [day[6] for day in weeks if day[6]]
add_event(events,
"Sunday Evening Service 6:00pm",
"Sunday Eventing Service",
"Starts at 6:00 PM.",
datetime(year, month, days[0], 18, 00, 00),
datetime(year, month, days[0], 19, 00, 00),
)
add_event(events,
"Sunday Service 10:00am",
"Sunday Service",
"Prayer Room open from 8:30 AM to 9:30 AM. Worship Service "
"starts at 10:00 AM. First Sunday of the month is "
"Missions Sunday.",
datetime(year, month, days[0], 10, 00, 00),
datetime(year, month, days[0], 12, 00, 00),
)
add_event(events,
"Sunday Evening Service 6:00pm",
"Sunday Eventing Service",
"Starts at 6:00 PM.",
datetime(year, month, days[1], 18, 00, 00),
datetime(year, month, days[1], 19, 00, 00),
)
add_event(events,
"Sunday Service 10:00am",
"Sunday Service",
"Prayer Room open from 8:30 AM to 9:30 AM. Worship Service "
"starts at 10:00 AM. Second Sunday of the month is "
"Baptism Sunday.",
datetime(year, month, days[1], 10, 00, 00),
datetime(year, month, days[1], 12, 00, 00),
)
add_event(events,
"Sunday Evening Service 6:00pm",
"Sunday Eventing Service",
"Starts at 6:00 PM.",
datetime(year, month, days[2], 18, 00, 00),
datetime(year, month, days[2], 19, 00, 00),
)
add_event(events,
"Sunday Service 10:00am",
"Sunday Service",
"Prayer Room open from 8:30 AM to 9:30 AM. Worship Service "
"starts at 10:00 AM. Third Sunday of the month is "
"Communion Sunday.",
datetime(year, month, days[2], 10, 00, 00),
datetime(year, month, days[2], 12, 00, 00),
)
add_event(events,
"Sunday Evening Service 6:00pm",
"Sunday Eventing Service",
"Starts at 6:00 PM.",
datetime(year, month, days[3], 18, 00, 00),
datetime(year, month, days[3], 19, 00, 00),
)
add_event(events,
"Sunday Service 10:00am",
"Sunday Service",
"Prayer Room open from 8:30 AM to 9:30 AM. Worship Service "
"starts at 10:00 AM. Fourth Sunday of the month is "
"Coins for Kids Sunday.",
datetime(year, month, days[3], 10, 00, 00),
datetime(year, month, days[3], 12, 00, 00),
)
if len(days) == 5:
add_event(events,
"Sunday Evening Service 6:00pm",
"Sunday Eventing Service",
"Starts at 6:00 PM.",
datetime(year, month, days[4], 18, 00, 00),
datetime(year, month, days[4], 19, 00, 00),
)
add_event(events,
"Sunday Service 10:00am",
"Sunday Service",
"Prayer Room open from 8:30 AM to 9:30 AM. Worship Service "
"starts at 10:00 AM. Fifth Sunday of the month is "
"Potluck Sunday",
datetime(year, month, days[4], 10, 00, 00),
datetime(year, month, days[4], 12, 00, 00),
)
def write_calendar(events: list[Event]) -> None:
"""write calendar to csv file""" """write calendar to csv file"""
with open("calendar.csv", "w", encoding="utf-8") as handle: with open(filename, "w", encoding="utf-8", newline="") as handle:
writer = DataclassWriter(handle, events, Event) writer = DataclassWriter(handle, events, Event)
writer.map("event_name").to("EVENT NAME") writer.map("event_name").to("EVENT NAME")
writer.map("venue_name").to("VENUE NAME") writer.map("venue_name").to("VENUE NAME")
@@ -410,23 +104,88 @@ def write_calendar(events: list[Event]) -> None:
writer.map("event_description").to("EVENT DESCRIPTION") writer.map("event_description").to("EVENT DESCRIPTION")
writer.write() writer.write()
def process_day(events, year, month, day, day_events):
"""process all events for one day"""
for event_item in day_events:
start = datetime(year, month, day, event_item[0], event_item[1])
finish = datetime(year, month, day, event_item[2], event_item[3])
debug_print(f" {start:%H:%M}-{finish:%H:%M} {event_item[6]:25} {event_item[4]:11} {event_item[5]:16} {event_item[7]:70.70}", DEBUG)
event = create_event(event_item[6], event_item[4], event_item[5], event_item[7].replace("\n","\\n"), start, finish)
events.append(event)
return events
def process_month(monthly_events, year, month, week, events, weekday_counters):
"""process one week of events using weekday occurrence counters"""
for day_of_week, day in enumerate(week):
if day > 0:
# Increment the occurrence count for this specific weekday (0=Mon, 6=Sun)
weekday_counters[day_of_week] += 1
current_occurrence = weekday_counters[day_of_week]
debug_print(f" {day_of_week}-{day:02d} (Occurrence: {current_occurrence})", DEBUG)
# Filter events matching this day of week and this specific occurrence (e.g., 2nd Monday)
day_events = [x[1:] for x in monthly_events[day_of_week] if current_occurrence in x[0]]
events = process_day(events, year, month, day, day_events)
return events
def process_months(months_dict, monthly_events, year, month_range):
"""process selected months and return list of events"""
events = []
for month in range(1, 13):
if month not in month_range:
continue
debug_print(f"MONTH: {month}", DEBUG)
# Initialize counters for the month to track 1st, 2nd, etc. occurrence of each weekday
weekday_counters = [0] * 7
for week_of_month, week in enumerate(months_dict[month]):
debug_print(f"{week_of_month} {week}", DEBUG)
events = process_month(monthly_events, year, month, week, events, weekday_counters)
return events
def validate_months(ctx, param, value):
"""Validates and processes the --months option."""
if value is None:
return list(range(1, 13))
parts = value.split('-')
if len(parts) == 1:
try:
month = int(parts[0])
if 1 <= month <= 12:
return [month]
raise click.BadParameter("Month must be between 1 and 12.")
except ValueError:
raise click.BadParameter("Invalid month format.")
elif len(parts) == 2:
try:
start, end = int(parts[0]), int(parts[1])
if 1 <= start <= 12 and 1 <= end <= 12 and start <= end:
return list(range(start, end + 1))
raise click.BadParameter("Invalid month range.")
except ValueError:
raise click.BadParameter("Invalid range format.")
raise click.BadParameter("Use a single number or a range (e.g., 1-3).")
@click.command() @click.command()
def main(): @click.option("--debug", "-d", is_flag=True, default=False, help="Print debug output")
"""create csv file""" @click.option('--year', "-y", type=int, default=date.today().year, help='Specify the year.')
events: list[Event] = [] @click.option('--months', '-m', 'month_range', callback=validate_months, default=None,
for month, weeks in MONTHS.items(): help='A single month (1-12) or a range (e.g., 1-3).')
add_tuesdays(events, YEAR, month, weeks) @click.argument('filename', default="calendar.csv", required=False)
add_wednesdays(events, YEAR, month, weeks) def main(debug, year, month_range, filename):
add_thursdays(events, YEAR, month, weeks) """Create a .csv file of church events for the year."""
add_fridays(events, YEAR, month, weeks) global DEBUG
add_saturdays(events, YEAR, month, weeks) DEBUG = debug
add_sundays(events, YEAR, month, weeks) months_dict = initalize_year(year)
monthly_events = initalize_events(EVENT_LIST)
events = sort_events(events) events = process_months(months_dict, monthly_events, year, month_range)
write_calendar(events) write_calendar(events, filename)
sys.exit(0) sys.exit(0)
if __name__ == "__main__": if __name__ == "__main__":
main() # pylint: disable=E1120 main()