commit 8e8517ffe3f6db4b3dfe810a134858de0f220729 Author: Fredrick W. Warren Date: Sun Dec 12 17:53:00 2021 -0800 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..031eec6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,150 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.envrc +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# NRB other files +*.pickle +*.vscode +.*.swp +*.db +*.sqlite +*.sqlite3 +error.* +test.py +*.csv diff --git a/README.md b/README.md new file mode 100644 index 0000000..5df6bff --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Program to generate a csv for importing calendar events diff --git a/main.py b/main.py new file mode 100755 index 0000000..92c8f88 --- /dev/null +++ b/main.py @@ -0,0 +1,230 @@ +#!/usr/bin/env python +""" +CHURCH CALENDAR CSV GENERATOR +""" + +import calendar +from dataclasses import dataclass +from datetime import datetime +# from pprint import pprint +import sys +import click +from dataclass_csv import DataclassWriter + + + +@dataclass +class Event(): + """Event for CSV export""" + # pylint: disable=too-many-instance-attributes + event_name: str + venue_name: str + organizer_name: str + start_date: str + start_time: str + end_date: str + end_time: str + all_day_event: str + categories: str + event_cost: str + event_phone: str + event_website: str + show_map_link: str + show_map: str + event_description: str + + +YEAR: int = 2022 +MONTHS: dict[int, list[list[int]]] +MONTHS = dict(enumerate([calendar.monthcalendar(2022, month) for month in + range(1, 13)], start=1)) + +def suffix(day: int) -> str: + """convert day to suffix""" + result: str = 'th' + if day in [1, 21, 31]: + result = 'st' + elif day in [2, 22]: + result = 'nd' + elif day in [3, 23]: + result = 'rd' + return result + + +def sort_events(events: list[Event]) -> list[Event]: + """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, + description: str, + start, + finish) -> None: + """create event""" + # pylint: disable=too-many-arguments + event = Event(name, + "Main Campus", + "", + start.strftime("%Y-%m-%d"), + start.strftime("%I:%M %p"), + finish.strftime("%Y-%m-%d"), + finish.strftime("%I:%M %p"), + "FALSE", + categories, + "", + "", + "", + "", + "", + description) + events.append(event) + +def add_wednesdays(events: list[Event], + year: int, + month: int, + weeks: list[list[int]]) -> None: + """add Wednesday events to calendar""" + + day = weeks[1][3] + add_event(events, + "Mid Week Service 6:00pm", + "Mid Week Service", + "", + # datetime(year, month, weeks[1][3], 19, 00, 00), + datetime(year, month, day, 15, 21, 00, 00), + datetime(year, month, day,15, 21, 00, 00), + # datetime(year, month, weeks[1][3], 21, 00, 00), + ) + +def add_thursdays(events: list[Event], + year: int, + month: int, + weeks: list[list[int]]) -> None: + """add Thursday events to calendar""" + + add_event(events, + "Woman’s Meeting 10:00am", + "Woman’s Meeting", + "Woman 2 Woman Bible Study", + datetime(year, month, weeks[1][4], 19, 00, 00), + datetime(year, month, weeks[1][4], 21, 00, 00), + ) + +def add_fridays(events: list[Event], + year: int, + month: int, + weeks: list[list[int]]) -> None: + """add Friday events to calendar""" + if len(weeks) == 4 or weeks[4][4] == 0: + return + + add_event(events, + "Family Movie Night 7:00pm", + "Movie Night", + "Movie to be announced", + datetime(year, month, weeks[4][4], 19, 00, 00), + datetime(year, month, weeks[4][4], 21, 00, 00), + ) + +def add_saturdays(events: list[Event], + year: int, + month: int, + weeks: list[list[int]]) -> None: + """add Saturday events to calendar""" + + add_event(events, + "Men's Breakfast 8:00am", + "Men's Meeting", + "", + datetime(year, month, weeks[1][5], 19, 00, 00), + datetime(year, month, weeks[1][5], 21, 00, 00), + ) + +def add_sundays(events: list[Event], + year: int, + month: int, + weeks: list[list[int]]) -> None: + """add Sunday events to calendar""" + 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, weeks[0][6], 10, 00, 00), + datetime(year, month, weeks[0][6], 12, 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, weeks[1][6], 10, 00, 00), + datetime(year, month, weeks[1][6], 12, 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, weeks[2][6], 10, 00, 00), + datetime(year, month, weeks[2][6], 12, 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, weeks[3][6], 10, 00, 00), + datetime(year, month, weeks[3][6], 12, 00, 00), + ) + + +def write_calendar(events: list[Event]) -> None: + """write calendar to csv file""" + 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") + writer.map("organizer_name").to("ORGANIZER NAME") + writer.map("start_date").to("START DATE") + writer.map("start_time").to("START TIME") + writer.map("end_date").to("END DATE") + writer.map("end_time").to("END TIME") + writer.map("all_day_event").to("ALL DAY EVENT") + writer.map("categories").to("CATEGORIES") + writer.map("event_cost").to("EVENT COST") + writer.map("event_phone").to("EVENT PHONE") + writer.map("event_website").to("EVENT_WEBSITE") + writer.map("show_map_link").to("SHOW MAP LINK?") + writer.map("show_map").to("SHOW MAP?") + writer.map("event_description").to("EVENT DESCRIPTION") + writer.write() + +@click.command() +def main(): + """create csv file""" + events: list[Event] = [] + for month, weeks in MONTHS.items(): + 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) + + +if __name__ == "__main__": + main() # pylint: disable=E1120 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1d4bcf7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +click==8.0.3 +dataclass-csv==1.3.0 +typing_extensions==4.0.1