Library provides a graphical view of the calendar.
Project description
Library provides a graphical view of the calendar. View, title and events can be easily configured.
The output in *.png file.
Input parameters
Configuration
Configuration for the all view can be done using CalendarConfig class.
Parameter |
Type |
Description |
---|---|---|
lang |
str |
Language, which is used for name of the weekday. Supported values: en, ru, ua. Default value: en |
title |
str |
Title of the view. Can be empty |
dates |
str |
The range of the days to show. Default value: ‘Mo - Su’ |
days |
int |
If dates does not exist, the number of days to display can be configured starting from Monday. For example, ‘4’ means dates='Mo - Th' |
hours |
str |
Hour range to display |
mode |
str |
|
show_date |
bool |
Defines is the date has to be shown. Format: 'dd.mm' or 'dd.mm.YYYY' if show_year=True. Default value: True |
show_year |
bool |
Defines is the year has to be added to the date format. Omitted if show_date=False. Default value: False |
legend |
bool |
If False - draw the name of the event inside the block. If True - draw the name in the legend. If not defined, will be chosen automatically. |
Example:
config = CalendarConfig(
lang='en',
title='Yoga Class Schedule',
dates='Mo - Fr',
hours='8 - 22',
mode=None,
show_date=True,
show_year=False,
legend=True,
)
# you can validate your config
validate_config(config)
Event
Parameter |
Type |
Description |
---|---|---|
name |
str |
Language, which is used for name of the weekday. Supported values: en, ru, ua |
day |
str |
Title of the view. Can be empty |
day_of_week |
int |
The range of the days to show. |
start_time |
str |
Start of the event in format HH:mm or HH. Can’t be used together with interval. |
end_time |
str |
End of the event in format HH:mm or HH. Can’t be used together with interval. |
interval |
str |
Start and end of the event in format HH:mm - HH:mm or HH - HH. Can’t be used together with start_time and end_time. |
Dates
The date can be defines using next rules.
Allowed year range: [1900, 2100]
Any delimiter from the list can be used:
-
.
/
Allowed formats:
YYYY.mm.dd
dd.mm.YYYY
dd.mm.YY - will use 20th century
dd.mm - for the current year
As an example, let’s look for example at the same data in all formats (assume, that current year is 2019):
2019-06-21
21.06.2019
21/06/19
21/06
Examples
1. Basic usage
Most basic and simplest usage. Doesn’t have configuration.
Code:
from calendar_view.core import data
from calendar_view.calendar import Calendar
calendar = Calendar.build()
calendar.add_event(data.event(day_of_week=0, interval='08:00 - 17:00'))
calendar.add_event(data.event(day_of_week=5, interval='10:00 - 13:00'))
calendar.add_event(data.event(day_of_week=6, interval='15:00 - 18:00'))
calendar.save("simple_view.png")
Output:
2. Configuration and specific dates
View for one script. Configuration object and events with specific dates are used.
Code:
from calendar_view.core import data
from calendar_view.calendar import Calendar
config = data.CalendarConfig(
lang='en',
title='Sprint 23',
dates='2019-09-23 - 2019-09-27',
show_year=True,
mode='working_hours',
legend=False,
)
events = [
data.event('Planning', date='2019-09-23', interval='11:00 - 13:00'),
data.event('Demo', date='2019-09-27', interval='15:00 - 16:00'),
data.event('Retrospective', date='2019-09-27', interval='17:00 - 18:00'),
]
data.validate_config(config)
data.validate_events(events, config)
calendar = Calendar.build(config)
calendar.add_events(events)
calendar.save("sprint_23.png")
Output:
3. Legend view
If the name of event is too long, it can ee printed in the legend.
Code:
from calendar_view.core import data from calendar_view.core.config import CalendarConfig from calendar_view.core.data import event from calendar_view.calendar import Calendar config = CalendarConfig( lang='en', title='Yoga Class Schedule', dates='Mo - Su', hours='8 - 22', show_date=False, legend=True, ) events = [ event(day_of_week=0, interval='11:00 - 12:30', name='Ashtanga, 90 mins, with Gina'), event(day_of_week=1, interval='18:00 - 19:15', name='HOT Core Yoga, 75 mins, with David'), event(day_of_week=2, interval='09:00 - 10:00', name='Meditation - Yoga Nidra, 60 mins, with Heena'), event(day_of_week=2, interval='19:00 - 20:15', name='Hatha Yoga, 75 mins, with Jo'), event(day_of_week=3, interval='19:00 - 20:00', name='Pilates, 60 mins, with Erika'), event(day_of_week=4, interval='18:30 - 20:00', name='Kundalini Yoga, 90 mins, with Dan'), event(day_of_week=5, interval='10:00 - 11:15', name='Hatha Yoga, 75 mins, with Amelia'), event(day_of_week=6, interval='10:00 - 11:15', name='Yoga Open, 75 mins, with Klaudia'), event(day_of_week=6, interval='14:00 - 15:15', name='Hatha Yoga, 75 mins, with Vick'), ] data.validate_config(config) data.validate_events(events, config) calendar = Calendar.build(config) calendar.add_events(events) calendar.save("yoga_class.png")
Output:
License
CalendarView is licensed under a MIT license. Please see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for calendar_view-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8c94e5e94fc5076d2ef10f9e5ea8d5acb0290cd0440c2678f4299112ccc1327 |
|
MD5 | 18422371c6f68d4b9ce9cb9b7347d9fc |
|
BLAKE2b-256 | 924a762b5a8ccea7c8c7843a2870285b8f17f319df2a945e8c72807fe721cba5 |