feat: add programmatic usage example to README
All checks were successful
Python Package CI/CD / Publish to PyPI (push) Successful in 42s

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.
This commit is contained in:
Kumi 2024-06-14 07:24:46 +02:00
parent 4a6c825394
commit 1e9430c2e7
Signed by: kumi
GPG key ID: ECBCC9082395383F
3 changed files with 25 additions and 2 deletions

View file

@ -72,6 +72,29 @@ kalente --help
For example, you may want to look into the `--end-date` and `--count` options For example, you may want to look into the `--end-date` and `--count` options
to generate calendars for multiple weeks or months. 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 ## License
Kalente is licensed under the MIT license. See the [LICENSE](LICENSE) file for Kalente is licensed under the MIT license. See the [LICENSE](LICENSE) file for

View file

@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project] [project]
name = "kalente" name = "kalente"
version = "0.2.0" version = "0.2.1"
authors = [ authors = [
{ name="Kumi Mitterer", email="kalente@kumi.email" }, { name="Kumi Mitterer", email="kalente@kumi.email" },
] ]

View file

@ -124,7 +124,7 @@ class Calendar:
raise ValueError("Invalid content type: {}".format(content_type)) raise ValueError("Invalid content type: {}".format(content_type))
@staticmethod @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("page-size", "A4")
options.setdefault("orientation", "Landscape") options.setdefault("orientation", "Landscape")
pdfkit.from_string(content, output_filename, options=options) pdfkit.from_string(content, output_filename, options=options)