Skip to main content

Library provides a graphical view of the calendar.

Project description

PyPi Package Version Supported Python versions PyPi Package Monthly Download MIT License

Calendar View

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

Mode will override some parameters. Available modes:
  • ‘week’ - show current week

  • ‘day_hours’ - show hours range ‘8:00 - 22:00’

  • ‘working_hours’ - show hours range ‘8:00 - 19:00’

  • ‘auto’ - modes ‘week’ + ‘day_hours’

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 / date / datetime

The day of the event. Can be set using any of 3 different types. Can’t be defined together with day_of_week

day_of_week

int

The range of the days to show. Can’t be defined together with day

start

str / time / datetime

Start of the event. Can be set using any of 3 different types. String has format HH:mm or HH.

end

str / time / datetime

End of the event. Can be set using any of 3 different types. String has format HH:mm or HH.

Dates

The date can be defines using next rules.

  1. Allowed year range: [1900, 2100]

  2. Any delimiter from the list can be used:

    • -

    • .

    • /

  3. 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.calendar import Calendar
from calendar_view.core.event import EventStyles

calendar = Calendar.build()
calendar.add_event(day_of_week=0, start='08:00', end='17:00', style=EventStyles.GRAY)
calendar.add_event(day_of_week=5, start='10:00', end='13:00', style=EventStyles.BLUE)
calendar.add_event(day_of_week=6, start='15:00', end='18:00')
calendar.save("simple_view.png")

Output:

https://raw.githubusercontent.com/sakhnevych/CalendarView/master/docs/simple_view.png

2. Configuration and specific dates

View for one script. Configuration object and events with specific dates are used.

Code:

from calendar_view.calendar import Calendar
from calendar_view.core import data
from calendar_view.core.event import Event

config = data.CalendarConfig(
    lang='en',
    title='Sprint 23',
    dates='2019-09-23 - 2019-09-27',
    show_year=True,
    mode='working_hours',
    legend=False,
)
events = [
    Event('Planning', day='2019-09-23', start='11:00', end='13:00'),
    Event('Demo', day='2019-09-27', start='15:00', end='16:00'),
    Event('Retrospective', day='2019-09-27', start='17:00', end='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:

https://raw.githubusercontent.com/sakhnevych/CalendarView/master/docs/sprint_23.png

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.calendar import Calendar
from calendar_view.core.event import Event

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, start='11:00', end='12:30', name='Ashtanga, 90 mins, with Gina', style=EventStyles.GRAY),
    Event(day_of_week=1, start='18:00', end='19:15', name='HOT Core Yoga, 75 mins, with David', style=EventStyles.RED),
    Event(day_of_week=2, start='09:00', end='10:00', name='Meditation - Yoga Nidra, 60 mins, with Heena', style=EventStyles.BLUE),
    Event(day_of_week=2, start='19:00', end='20:15', name='Hatha Yoga, 75 mins, with Jo', style=EventStyles.GREEN),
    Event(day_of_week=3, start='19:00', end='20:00', name='Pilates, 60 mins, with Erika', style=EventStyles.GRAY),
    Event(day_of_week=4, start='18:30', end='20:00', name='Kundalini Yoga, 90 mins, with Dan', style=EventStyles.RED),
    Event(day_of_week=5, start='10:00', end='11:15', name='Hatha Yoga, 75 mins, with Amelia', style=EventStyles.GREEN),
    Event(day_of_week=6, start='10:00', end='11:15', name='Yoga Open, 75 mins, with Klaudia', style=EventStyles.BLUE),
    Event(day_of_week=6, start='14:00', end='15:15', name='Hatha Yoga, 75 mins, with Vick', style=EventStyles.GREEN)
]

data.validate_config(config)
data.validate_events(events, config)

calendar = Calendar.build(config)
calendar.add_events(events)
calendar.save("yoga_class.png")

Output:

https://raw.githubusercontent.com/sakhnevych/CalendarView/master/docs/yoga_class.png

License

CalendarView is licensed under a MIT license. Please see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

calendar-view-1.1.0.tar.gz (174.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

calendar_view-1.1.0-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file calendar-view-1.1.0.tar.gz.

File metadata

  • Download URL: calendar-view-1.1.0.tar.gz
  • Upload date:
  • Size: 174.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.7

File hashes

Hashes for calendar-view-1.1.0.tar.gz
Algorithm Hash digest
SHA256 e4c9732bbe2fccc63d8703af6937a997a4ca722aa1270256bd40cfc8b10bdd97
MD5 5be2608b2c3d53d83c8b9c139ef0c836
BLAKE2b-256 880662349ab299077489303cbd82c933703b0fa3337b2bcbc7d60ef499769111

See more details on using hashes here.

File details

Details for the file calendar_view-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: calendar_view-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.7

File hashes

Hashes for calendar_view-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 365566537cb2449c8f2d776b30c569b758107d1352f8fcf83bbfa6df66d7b894
MD5 cfb085de2820ff9dfafcaf612f8813c5
BLAKE2b-256 07145ffc53c32e842e0a34d119cfa89ff1cca277660159cba3b64ba2af78e9b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page