Compare commits

..

No commits in common. "2ecb916a2fb8711681d92ed005d1fcabc84493cd" and "065fbb36844a29e98358ab5da856e08438cc9678" have entirely different histories.

2 changed files with 334 additions and 130 deletions

View File

@ -1,31 +0,0 @@
#!/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,56 +5,14 @@ CHURCH CALENDAR CSV GENERATOR
import calendar
from dataclasses import dataclass
from datetime import date, datetime
from pprint import pprint
from datetime import 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"""
@ -75,6 +33,12 @@ 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'
@ -92,8 +56,8 @@ def sort_events(events: list[Event]) -> list[Event]:
events = sorted(events, key=lambda k: (k.start_date, k.start_time))
return events
def create_event(name: str,
location: str,
def add_event(events: list[Event],
name: str,
categories: str,
description: str,
start,
@ -101,7 +65,7 @@ def create_event(name: str,
"""create event"""
# pylint: disable=too-many-arguments
event = Event(name,
location,
"Main Campus",
"",
start.strftime("%Y-%m-%d"),
start.strftime("%I:%M %p"),
@ -115,13 +79,319 @@ def create_event(name: str,
"",
"",
description)
return event
# events.append(event)
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),
)
def write_calendar(events: list[Event], filename) -> None:
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:
"""write calendar to csv file"""
with open(filename, "w", encoding="utf-8") as handle:
with open("calendar.csv", "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")
@ -140,56 +410,21 @@ def write_calendar(events: list[Event], filename) -> 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()
@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):
def main():
"""create csv file"""
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)
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)
sys.exit(0)