Compare commits

...

20 Commits

Author SHA1 Message Date
2ecb916a2f pass filename to writer, default calendar.csv 2024-12-29 10:20:36 -07:00
9707095cc1 repalced global MONTHS with local months 2024-12-29 10:01:32 -07:00
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
bf5234aa6e YEAR is now a default command line option in main 2024-12-29 09:53:31 -07:00
71222aa59c convert newlines in descrption field to \n 2024-12-29 08:50:37 -07:00
0b97ad1e49 added actuall event creation 2024-12-29 08:23:16 -07:00
6b39ed588d delete junk file 3q 2024-12-29 07:48:21 -07:00
bfa5d994a9 corrected spelling of Coffee 2024-12-29 07:46:23 -07:00
889022c84c added processing events by day 2024-12-29 07:46:00 -07:00
f786cceed1 updated debug print 2024-12-29 07:41:15 -07:00
a77019638d setup debug printing 2024-12-29 07:30:41 -07:00
037981040a moved processing into months and month 2024-12-29 07:20:53 -07:00
284885c221 moved processing from main to process_year 2024-12-29 07:05:07 -07:00
ea9d02a03a rework main and enabled Click 2024-12-29 06:47:04 -07:00
84674d8ae5 renamed processed EVENTS to monthly_events 2024-12-29 06:46:28 -07:00
a8cfff3dfe enabled all includes 2024-12-29 06:44:43 -07:00
caa70cc69b changed format of events 2024-12-28 20:18:36 -07:00
0e8637edff documented EVENT_LIST 2024-12-28 10:36:08 -07:00
fe5b7eaae0 reformatted due to adding week 6 to Tuesday 2024-12-28 10:34:26 -07:00
a85fa66954 Moved Event defintions to new file 2024-12-27 22:01:57 -07:00
2 changed files with 130 additions and 334 deletions

31
events.py Executable file
View File

@ -0,0 +1,31 @@
#!/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
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"),
(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."),
(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 ], 7, 00, 8, 00, "SOCO", "Youth Group", "Youth Bible Study 7:00am", "Coffee and bible study for high school age youth"),
(WEDNESDAY, [2 ], 8, 00, 12, 00, "Main Campus", "Connecting Point", "Connecting Point 8:00am", ""),
(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 ], 18, 00, 20, 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, [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

433
main.py
View File

@ -5,14 +5,56 @@ CHURCH CALENDAR CSV GENERATOR
import calendar
from dataclasses import dataclass
from datetime import datetime
# from pprint import pprint
from datetime import date, datetime
from pprint import pprint
import sys
import click
from dataclass_csv import DataclassWriter
from events import EVENT_LIST
"""
build a list of months / weeks / day of the month in those weeks
months 1-12, weeks 0-5 days of week 5 6 are the 1st and 2nd of month
MONTHS[1] [0] [ 0 0 0 0 0 1 2 ]
due to how months work
week 0 can have null days (represented by 0's)
weeks 1 - 4 will have all 7 days present
week 5 may have 7 days or nulls
week 6 can have a monday and/or tuesday in them if the 1st falls on a
saturday or sunday in week 0
EVENT_LIST has weeks as 1-6 while MONTHS has weeks as 0-5, offsetting will
be necessary
"""
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 using pprint.
Args:
data: The data to be printed.
condition: A boolean value. If True, the data will be printed.
"""
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
class Event():
"""Event for CSV export"""
@ -33,12 +75,6 @@ class Event():
show_map: 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:
"""convert day to suffix"""
result: str = 'th'
@ -56,8 +92,8 @@ def sort_events(events: list[Event]) -> list[Event]:
events = sorted(events, key=lambda k: (k.start_date, k.start_time))
return events
def add_event(events: list[Event],
name: str,
def create_event(name: str,
location: str,
categories: str,
description: str,
start,
@ -65,7 +101,7 @@ def add_event(events: list[Event],
"""create event"""
# pylint: disable=too-many-arguments
event = Event(name,
"Main Campus",
location,
"",
start.strftime("%Y-%m-%d"),
start.strftime("%I:%M %p"),
@ -79,319 +115,13 @@ def add_event(events: list[Event],
"",
"",
description)
events.append(event)
def add_tuesdays(events: list[Event],
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),
)
return event
# events.append(event)
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,
"Womans Meeting 10:00am",
"Womans 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,
"Womans Meeting 10:00am",
"Womans 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,
"Womans Meeting 10:00am",
"Womans 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,
"Womans Meeting 10:00am",
"Womans 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,
"Womans Meeting 10:00am",
"Womans 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",
"Mens 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",
"Mens 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",
"Mens 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",
"Mens 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:
def write_calendar(events: list[Event], filename) -> None:
"""write calendar to csv file"""
with open("calendar.csv", "w", encoding="utf-8") as handle:
with open(filename, "w", encoding="utf-8") as handle:
writer =DataclassWriter(handle, events, Event)
writer.map("event_name").to("EVENT NAME")
writer.map("venue_name").to("VENUE NAME")
@ -410,21 +140,56 @@ def write_calendar(events: list[Event]) -> None:
writer.map("event_description").to("EVENT DESCRIPTION")
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(months, monthly_events, year, month, week_of_month, week, events):
"""process one months of events"""
for day_of_week, day in enumerate(week):
if day > 0:
"""
month, week_of_month, day_of_week, day
use monthly_events[day_of_week]
"""
debug_print(f" {day_of_week}-{day:02d}", DEBUG)
day_events = [x[1:] for x in monthly_events[day_of_week] if week_of_month + 1 in x[0]]
events = process_day(events, year, month, day, day_events)
debug_print("", DEBUG)
return events
def process_months(months, monthly_events, year):
"""process full year of months and return list of events"""
events = []
for month in range(1, 13):
debug_print(f"MONTH: {month}", DEBUG)
for week_of_month, week in enumerate(months[month]):
debug_print(f"{week_of_month} {week}", DEBUG)
events = process_month(months, monthly_events, year, month, week_of_month, week, events)
return events
# @click.argument('filename', type=click.File('w'), default="calendar.csv", required=False)
@click.command()
def main():
@click.option("--debug", "-d", is_flag=True, default=False, help="Print debug output")
@click.option('--year', "-y", type=int, default=date.today().year, help='Specify the year.')
@click.argument('filename', default="calendar.csv", required=False)
def main(debug, year, filename):
"""create csv file"""
events: list[Event] = []
for month, weeks in MONTHS.items():
add_tuesdays(events, YEAR, month, weeks)
add_wednesdays(events, YEAR, month, weeks)
add_thursdays(events, YEAR, month, weeks)
add_fridays(events, YEAR, month, weeks)
add_saturdays(events, YEAR, month, weeks)
add_sundays(events, YEAR, month, weeks)
events = sort_events(events)
write_calendar(events)
global DEBUG
DEBUG = debug
months = initalize_year(year)
monthly_events = initalize_events(EVENT_LIST)
events = process_months(months, monthly_events, year)
# events = sort_events(events)
write_calendar(events, filename)
sys.exit(0)