From 1e9430c2e73c328feb92f9ce29c0a4edbac1451c Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 14 Jun 2024 07:24:46 +0200 Subject: [PATCH] feat: add programmatic usage example to README Added an example in README for generating a weekly calendar programmatically using Kalente. This assists developers by demonstrating how to integrate Kalente into their projects. fix: default options parameter in convert_html_to_pdf Updated the `options` parameter in `convert_html_to_pdf` to default to an empty dictionary. This prevents potential NoneType errors and ensures consistent behavior. chore: bump version to 0.2.1 Updated version in pyproject.toml to reflect the new features and bug fixes. --- README.md | 23 +++++++++++++++++++++++ pyproject.toml | 2 +- src/kalente/classes/calendar.py | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a8dad7d..99b1311 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,29 @@ kalente --help For example, you may want to look into the `--end-date` and `--count` options to generate calendars for multiple weeks or months. +## Programmatic Usage + +Kalente can also be used programmatically. Here's an example of how you can +generate a weekly calendar using Kalente: + +```python +from kalente import Calendar +from datetime import date + +# Create a Calendar object, optionally specifying the country to use +# for holidays, and a date format. +calendar = Calendar(country_code="AT", date_format="%d %B %Y") + +# Get week data for the week of January 1st, 2021. +data = calendar.get_week(date(2021, 1, 1)) + +# Generate HTML for the week. +html = Calendar.generate_html(data, type="weekly") + +# Generate a PDF file for the week. +Calendar.convert_html_to_pdf(html, "weekly.pdf") +``` + ## License Kalente is licensed under the MIT license. See the [LICENSE](LICENSE) file for diff --git a/pyproject.toml b/pyproject.toml index e04053b..44f0e14 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "kalente" -version = "0.2.0" +version = "0.2.1" authors = [ { name="Kumi Mitterer", email="kalente@kumi.email" }, ] diff --git a/src/kalente/classes/calendar.py b/src/kalente/classes/calendar.py index 4dcaa99..7c4151c 100644 --- a/src/kalente/classes/calendar.py +++ b/src/kalente/classes/calendar.py @@ -124,7 +124,7 @@ class Calendar: raise ValueError("Invalid content type: {}".format(content_type)) @staticmethod - def convert_html_to_pdf(content, output_filename, options=None): + def convert_html_to_pdf(content, output_filename, options={}): options.setdefault("page-size", "A4") options.setdefault("orientation", "Landscape") pdfkit.from_string(content, output_filename, options=options)