From 34d10270d6e860b34b4f6f70fa567188a2426443 Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Wed, 17 Jul 2024 15:41:01 +0200 Subject: [PATCH] Module structure --- README.md => kobo_wall_calendar/__init__.py | 16 +++++---- main.py => kobo_wall_calendar/__main__.py | 33 ++++++++++--------- kobo_wall_calendar/_version.py | 1 + .../google_calendar.py | 2 +- requirements.txt | 4 +++ setup.py | 1 + 6 files changed, 34 insertions(+), 23 deletions(-) rename README.md => kobo_wall_calendar/__init__.py (53%) rename main.py => kobo_wall_calendar/__main__.py (81%) create mode 100644 kobo_wall_calendar/_version.py rename google_calendar.py => kobo_wall_calendar/google_calendar.py (92%) create mode 100644 requirements.txt create mode 100644 setup.py diff --git a/README.md b/kobo_wall_calendar/__init__.py similarity index 53% rename from README.md rename to kobo_wall_calendar/__init__.py index 24aa2b9..eb4ded2 100644 --- a/README.md +++ b/kobo_wall_calendar/__init__.py @@ -1,19 +1,21 @@ - -# Kobo Calendar Server +"""# Kobo Calendar Server Small calendar web-server pulling from ICAL files, and presenting events in -a lightweight html frontend. +a lightweight HMTL frontend. -The motivation was to create a lightweight wall calendar to use with an old Kobo -Aura e-reader, to take advantage of the it's e-ink screen. +The motivation was to create a lightweight wall calendar to use with an old +[Kobo Aura e-reader](https://en.wikipedia.org/wiki/Kobo_Aura), to take +advantage of the its e-ink screen, but I had problems getting it to run 24/7. ## Example usage 1. Edit `config.py` to include links to your ICAL files. (Google Calendar hidden ICAL links works great here.) 2. Launch server using something like: `python main.py --port 8082 --hostname 192.168.87.197` -3. Navigate to [192.168.87.197:8082](http://192.168.87.197:8082/). +3. Navigate to . 4. Enjoy +""" +__all__ = ['__version__'] - +from _version import __version__ diff --git a/main.py b/kobo_wall_calendar/__main__.py similarity index 81% rename from main.py rename to kobo_wall_calendar/__main__.py index 6705a82..9d33526 100644 --- a/main.py +++ b/kobo_wall_calendar/__main__.py @@ -2,7 +2,7 @@ import argparse import bottle import datetime -import google_calendar +from . import google_calendar import config @@ -39,13 +39,7 @@ def render_calendar(events_map, today): header = today.strftime('%B %Y') return TEMPLATE_INDEX.render(days = days, header = header) -## Paths - -@bottle.route('/static/') -def static(path): - return bottle.static_file(path, root = './static') - -def get_events_map(): +def get_events_map() -> tuple[dict[datetime.date, list[str]], datetime.date]: today = datetime.date.today() events_map = { } for prefix, url in config.ICAL_LINKS.items(): @@ -56,19 +50,28 @@ def get_events_map(): return events_map, today +## Paths + +@bottle.route('/static/') +def static(path): + return bottle.static_file(path, root = './static') + @bottle.route('/') -def reddit_index(): +def month_calendar(): events_map, today = get_events_map() return render_calendar(events_map, today) -## Argument parsing -parser = argparse.ArgumentParser() -parser.add_argument('--hostname', action='store', default = 'localhost', dest='hostname') -parser.add_argument('--port', action='store', default = 8080, dest='port', type = int) - -if __name__ == '__main__': +def main(): + ## Argument parsing + parser = argparse.ArgumentParser() + parser.add_argument('--hostname', action='store', default = 'localhost', dest='hostname') + parser.add_argument('--port', action='store', default = 8080, dest='port', type = int) args = parser.parse_args() + + # Initialization bottle.run(host=args.hostname, port=args.port) +if __name__ == '__main__': + main() diff --git a/kobo_wall_calendar/_version.py b/kobo_wall_calendar/_version.py new file mode 100644 index 0000000..b794fd4 --- /dev/null +++ b/kobo_wall_calendar/_version.py @@ -0,0 +1 @@ +__version__ = '0.1.0' diff --git a/google_calendar.py b/kobo_wall_calendar/google_calendar.py similarity index 92% rename from google_calendar.py rename to kobo_wall_calendar/google_calendar.py index 0b6baf1..ac2e423 100644 --- a/google_calendar.py +++ b/kobo_wall_calendar/google_calendar.py @@ -10,7 +10,7 @@ logger = logging.getLogger(__name__) SESSION = requests_cache.CachedSession('calendar') @functools.cache -def get_events_for_month(ical_link, today): +def get_events_for_month(ical_link: str, today: datetime.date): logger.warning('Downloading ical from Google') response = SESSION.get(ical_link) assert response.status_code == 200 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5df32a8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +ical +requests_cache +secret_loader @ git@gitfub.space:Jmaa/secret_loader.git +bottle diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..3be9693 --- /dev/null +++ b/setup.py @@ -0,0 +1 @@ +# Bogus