### Install isdayoff Python Package Source: https://github.com/kobylinskii-m/isdayoff/blob/master/README.md This command installs the isdayoff Python package using pip, making the Production Calendar API accessible in your Python projects. Ensure you have pip installed. ```bash pip install isdayoff ``` -------------------------------- ### Get Month Calendar Data with isdayoff Source: https://context7.com/kobylinskii-m/isdayoff/llms.txt This snippet demonstrates how to retrieve working and non-working day information for a specific month using the `isdayoff` library. It shows how to parse the returned dictionary to count different types of days and how to use optional parameters for more detailed data. Ensure the `isdayoff` library is installed and `asyncio` is available. ```python import asyncio from datetime import date from isdayoff import ProdCalendar, DateType calendar = ProdCalendar(locale='ru') async def analyze_month(): try: # Get data for August 2021 month_data = await calendar.month(date(2021, 8, 1)) # month_data is a dict: {'2021.08.01': DateType.NOT_WORKING, ...} working_days = [d for d, status in month_data.items() if status == DateType.WORKING] days_off = [d for d, status in month_data.items() if status == DateType.NOT_WORKING] shortened = [d for d, status in month_data.items() if status == DateType.SHORTENED] print(f"August 2021 statistics:") print(f"Working days: {len(working_days)}") print(f"Days off: {len(days_off)}") print(f"Shortened days: {len(shortened)}") print(f"\nDays off: {days_off}") # Check with parameters detailed_data = await calendar.month( date(2021, 12, 1), locale='ru', pre=True, covid=True ) for day_str, day_type in list(detailed_data.items())[:5]: print(f"{day_str}: {day_type.name}") finally: await calendar.close() asyncio.run(analyze_month()) ``` -------------------------------- ### Basic Date Check with isdayoff in Python Source: https://context7.com/kobylinskii-m/isdayoff/llms.txt A simple asynchronous example demonstrating how to initialize ProdCalendar and check a specific date. It prints the descriptive name of the day type returned by the calendar. ```python import asyncio from datetime import date from isdayoff import ProdCalendar calendar = ProdCalendar(locale='ru') async def main(): result = await calendar.date(date(2021, 12, 31)) print(describe_day(result)) await calendar.close() asyncio.run(main()) ``` -------------------------------- ### Initialize Production Calendar Client - Python Source: https://context7.com/kobylinskii-m/isdayoff/llms.txt Initializes the ProdCalendar client with optional locale and base URL. This setup is necessary before making any date queries. The client manages asynchronous HTTP requests using aiohttp. Remember to close the calendar session when done. ```python import asyncio from isdayoff import ProdCalendar, DateType # Initialize with default Russian locale calendar = ProdCalendar() # Initialize with specific locale and custom date format calendar_us = ProdCalendar( locale='us', base_url='https://isdayoff.ru', format_date='%Y-%m-%d' ) async def example(): # Don't forget to close the session when done await calendar.close() await calendar_us.close() asyncio.run(example()) ``` -------------------------------- ### Count Days Off in a Month (Python Example) Source: https://github.com/kobylinskii-m/isdayoff/blob/master/README.md This Python example demonstrates how to count the number of days off in a specific month using the isdayoff library. It utilizes `asyncio` for asynchronous operations and fetches month data using `calendar.month()`. The snippet then iterates through the results to count occurrences of `DateType.NOT_WORKING`. ```python from isdayoff import ProdCalendar, DateType from datetime import date import asyncio calendar = ProdCalendar(locale='us') async def main(): res = await calendar.month(date(2021, 8, 1), locale='ru') count = len([DateType.NOT_WORKING for day in res if res[day] == DateType.NOT_WORKING]) print('Days off in a month', count) loop = asyncio.get_event_loop() loop.create_task(main()) loop.run_forever() ``` -------------------------------- ### Get Date Range Calendar Data with isdayoff Source: https://context7.com/kobylinskii-m/isdayoff/llms.txt This example shows how to query working/non-working day status for a custom date range using the `isdayoff` library. It includes examples of counting working and non-working days within the range and applying various parameters like locale, pre-holidays, COVID data, and shortened days. Requires `isdayoff` and `asyncio`. ```python import asyncio from datetime import date from isdayoff import ProdCalendar, DateType calendar = ProdCalendar(locale='ru') async def analyze_range(): try: # Get data from January 1 to May 1, 2021 range_data = await calendar.range_date( date(2021, 1, 1), date(2021, 5, 1) ) print(f"Range contains {len(range_data)} days") # Count working vs non-working days working = sum(1 for d in range_data.values() if d == DateType.WORKING) non_working = sum(1 for d in range_data.values() if d == DateType.NOT_WORKING) print(f"Working days: {working}") print(f"Days off: {non_working}") # Get range with parameters detailed_range = await calendar.range_date( date(2021, 12, 20), date(2022, 1, 10), locale='ru', pre=True, covid=True, sd=False ) # Print New Year period for day_str, day_type in detailed_range.items(): symbol = "✓" if day_type == DateType.WORKING else "✗" print(f"{symbol} {day_str}: {day_type.name}") finally: await calendar.close() asyncio.run(analyze_range()) ``` -------------------------------- ### Define and Use Date Types in Python Source: https://context7.com/kobylinskii-m/isdayoff/llms.txt Demonstrates how to define and use custom date types, such as 'Special working day', within the isdayoff library. It shows a practical example of describing different day types based on the DateType enum. ```python # DateType.WORKING_DAY = 4 # Special working day (COVID-19 related) # Usage in conditionals def describe_day(day_type: DateType) -> str: descriptions = { DateType.WORKING: "Regular working day", DateType.NOT_WORKING: "Holiday or weekend", DateType.SHORTENED: "Shortened working day (usually before holiday)", DateType.WORKING_DAY: "Special working day (COVID-19 adjustment)" } return descriptions.get(day_type, "Unknown day type") ``` -------------------------------- ### Check Dates and Handle Errors with isdayoff in Python Source: https://context7.com/kobylinskii-m/isdayoff/llms.txt Provides a comprehensive example of using the ProdCalendar class from the isdayoff library to check dates. It includes detailed error handling for various exceptions like DataError, ServiceNotRespond, and ValueError, ensuring robust API interaction. ```python import asyncio from datetime import date from isdayoff import ProdCalendar, DateType from isdayoff.typingapi import ServiceNotRespond, DataError calendar = ProdCalendar(locale='ru') async def safe_check_date(): try: # Try to check a potentially invalid date result = await calendar.date(date(2021, 8, 25)) if result == DateType.WORKING: print("It's a working day") else: print("It's not a working day") except DataError as e: print(f"Invalid date provided: {e}") except ServiceNotRespond as e: print(f"API service not responding: {e}") except ValueError as e: print(f"Invalid locale or parameter: {e}") except Exception as e: print(f"Unexpected error: {e}") finally: await calendar.close() asyncio.run(safe_check_date()) # Testing with invalid locale async def test_invalid_locale(): try: # This will raise ValueError bad_calendar = ProdCalendar(locale='invalid_country') except ValueError as e: print(f"Caught error: {e}") # Output: locale must be in ('ru', 'ua', 'kz', 'by', 'us') asyncio.run(test_invalid_locale()) ``` -------------------------------- ### Get Month's Day Information (Python) Source: https://github.com/kobylinskii-m/isdayoff/blob/master/README.md This Python snippet retrieves information about all days within a specific month using the isdayoff library. It takes a `date` object representing any day in the target month and optional parameters like `locale`, `pre`, `covid`, and `sd`. The function returns a dictionary containing the status of each day in the month. ```python await calendar.month(date(2021, 8, 1)) ``` -------------------------------- ### Get Date Range Information (Python) Source: https://github.com/kobylinskii-m/isdayoff/blob/master/README.md This Python snippet retrieves calendar information for a specified period using the isdayoff library. It takes `start_date` and `end_date` objects and optional parameters like `locale`, `pre`, `covid`, and `sd`. The function returns a dictionary containing the status for each day within the given range. ```python await calendar.range_date(date(2021, 1, 1), date(2021, 5, 1)) ``` -------------------------------- ### Get Year's Day Information (Python) Source: https://github.com/kobylinskii-m/isdayoff/blob/master/README.md This Python snippet fetches information about all days within a specific year using the isdayoff library. It requires a `date` object representing any day in the target year and supports optional parameters like `locale`, `pre`, `covid`, and `sd`. The function returns a dictionary with the status of each day in the year. ```python await calendar.year(date(2021, 1, 1)) ``` -------------------------------- ### Get Year Calendar Data with isdayoff Source: https://context7.com/kobylinskii-m/isdayoff/llms.txt This code snippet shows how to fetch working/non-working day data for an entire year using the `isdayoff` library. It iterates through the year's data to count various day types, including regular working days, holidays, shortened days, and COVID-related working days. Requires `isdayoff` and `asyncio`. ```python import asyncio from datetime import date from isdayoff import ProdCalendar, DateType calendar = ProdCalendar(locale='ru') async def analyze_year(): try: # Get data for entire year 2021 year_data = await calendar.year(date(2021, 1, 1)) # Count different day types stats = { 'working': 0, 'not_working': 0, 'shortened': 0, 'covid_working': 0 } for day_str, day_type in year_data.items(): if day_type == DateType.WORKING: stats['working'] += 1 elif day_type == DateType.NOT_WORKING: stats['not_working'] += 1 elif day_type == DateType.SHORTENED: stats['shortened'] += 1 elif day_type == DateType.WORKING_DAY: stats['covid_working'] += 1 print(f"Year 2021 statistics:") print(f"Total days: {len(year_data)}") print(f"Working days: {stats['working']}") print(f"Days off: {stats['not_working']}") print(f"Shortened days: {stats['shortened']}") print(f"COVID working days: {stats['covid_working']}") finally: await calendar.close() asyncio.run(analyze_year()) ``` -------------------------------- ### Python Work Schedule and Vacation Planner Source: https://context7.com/kobylinskii-m/isdayoff/llms.txt This Python script demonstrates how to use the isdayoff library to analyze weekly schedules, plan vacations by calculating working days, and count remaining working days in a year. It utilizes asynchronous programming for efficient calendar queries and proper session management. ```python import asyncio from datetime import date, datetime, timedelta from isdayoff import ProdCalendar, DateType class WorkScheduleAnalyzer: def __init__(self, locale='ru'): self.calendar = ProdCalendar(locale=locale) async def analyze_current_week(self): """Analyze the current week's work schedule.""" today = datetime.now().date() week_start = today - timedelta(days=today.weekday()) week_end = week_start + timedelta(days=6) week_data = await self.calendar.range_date(week_start, week_end) print(f"\n=== Week of {week_start} ===") for day_str, day_type in week_data.items(): status = "WORK" if day_type == DateType.WORKING else "OFF" print(f"{day_str}: {status}") return week_data async def plan_vacation(self, start_date, end_date): """Calculate actual vacation days (excluding weekends/holidays).""" vacation_data = await self.calendar.range_date(start_date, end_date) total_days = len(vacation_data) work_days = sum(1 for d in vacation_data.values() if d == DateType.WORKING) days_off = total_days - work_days print(f"\n=== Vacation Planning ===") print(f"Period: {start_date} to {end_date}") print(f"Total calendar days: {total_days}") print(f"Working days to take off: {work_days}") print(f"Free weekends/holidays: {days_off}") return work_days async def count_working_days_remaining(self, year): """Count remaining working days in the year.""" today = datetime.now().date() year_end = date(year, 12, 31) if today > year_end: print(f"Year {year} has already ended") return 0 remaining_data = await self.calendar.range_date(today, year_end) working_days = sum(1 for d in remaining_data.values() if d == DateType.WORKING) print(f"\n=== Remaining Work Days in {year} ===") print(f"Working days left: {working_days}") return working_days async def close(self): """Close the calendar session.""" await self.calendar.close() async def main(): analyzer = WorkScheduleAnalyzer(locale='ru') try: # Check today today_status = await analyzer.calendar.today() print(f"Today is: {today_status.name}") # Analyze current week await analyzer.analyze_current_week() # Plan a vacation vacation_start = date(2024, 6, 1) vacation_end = date(2024, 6, 14) await analyzer.plan_vacation(vacation_start, vacation_end) # Count remaining working days await analyzer.count_working_days_remaining(2024) # Check if next year is leap is_leap = analyzer.calendar.is_leap(date(2024, 1, 1)) print(f"\n2024 is {'a leap year' if is_leap else 'not a leap year'}") finally: await analyzer.close() if __name__ == '__main__': asyncio.run(main()) ``` -------------------------------- ### Check Today's Date Status with Parameters (Python) Source: https://github.com/kobylinskii-m/isdayoff/blob/master/README.md This Python snippet demonstrates how to check the status of the current day using the isdayoff library. It accepts several parameters: `locale` for country code, `pre` to mark shortened working days, `covid` to mark working days due to the pandemic, and `sd` to consider a six-day work week. The function returns the date type. ```python await calendar.today(locale='ru', pre=True, covid=True, sd=True) ``` -------------------------------- ### Check Leap Year with isdayoff Source: https://context7.com/kobylinskii-m/isdayoff/llms.txt This Python snippet demonstrates how to determine if a given year is a leap year using the `isdayoff` library's `is_leap` method. It checks a list of sample years and prints whether each is a leap year or not. Requires `isdayoff` and `asyncio`. ```python import asyncio from datetime import date from isdayoff import ProdCalendar calendar = ProdCalendar() async def check_leap_years(): years_to_check = [2020, 2021, 2024, 2100, 2000] for year in years_to_check: is_leap = calendar.is_leap(date(year, 1, 1)) print(f"{year}: {'Leap year' if is_leap else 'Not a leap year'}") await calendar.close() asyncio.run(check_leap_years()) ``` -------------------------------- ### Check if Tomorrow is a Working Day (Python) Source: https://github.com/kobylinskii-m/isdayoff/blob/master/README.md This Python snippet checks if tomorrow is a working day using the isdayoff library. It leverages asyncio for asynchronous operations and allows specifying a locale for calendar data. The output indicates whether tomorrow is a working day or a day off. ```python import asyncio from isdayoff import DateType, ProdCalendar calendar = ProdCalendar(locale='us') async def main(): if await calendar.tomorrow() == DateType.WORKING: print('Tomorrow is a working day') else: print('Tomorrow is a day off') loop = asyncio.get_event_loop() loop.create_task(main()) loop.run_forever() ``` -------------------------------- ### DateType Enumeration in isdayoff Source: https://context7.com/kobylinskii-m/isdayoff/llms.txt This snippet shows the `DateType` enumeration provided by the `isdayoff` library, which defines constants for different types of days recognized in a production calendar. These include regular working days, non-working days (holidays/weekends), and shortened working days. ```python from isdayoff import DateType # DateType values: # DateType.WORKING = 0 # Regular working day # DateType.NOT_WORKING = 1 # Holiday or weekend # DateType.SHORTENED = 2 # Shortened working day (pre-holiday) ``` -------------------------------- ### Check Weekend Status for a Specific Date (Python) Source: https://github.com/kobylinskii-m/isdayoff/blob/master/README.md This Python snippet checks if a specific date is a working day or a day off using the isdayoff library. It requires importing `date` from the `datetime` module and `ProdCalendar`, `DateType` from `isdayoff`. It supports various parameters like `locale`, `pre`, `covid`, and `sd` for detailed calendar analysis. ```python import asyncio from datetime import date from isdayoff import DateType, ProdCalendar calendar = ProdCalendar(locale='us') async def main(): if await calendar.date(date(2021, 8, 25)) == DateType.WORKING: print('Is a working day') else: print('Is a day off') ... ``` -------------------------------- ### Check Tomorrow's Date Status with Parameters - Python Source: https://context7.com/kobylinskii-m/isdayoff/llms.txt Checks if tomorrow is a working day, optionally including parameters like locale, and flags for shortened days, COVID-19 adjustments, and six-day work weeks. This provides a more detailed status of tomorrow's calendar. ```python import asyncio from isdayoff import ProdCalendar, DateType calendar = ProdCalendar(locale='us') async def check_tomorrow(): try: # Basic check result = await calendar.tomorrow() if result == DateType.WORKING: print("Tomorrow is a working day") else: print("Tomorrow is a day off") # Check with parameters: mark shortened days, consider COVID adjustments result_detailed = await calendar.tomorrow( locale='ru', pre=True, # Mark shortened working days covid=True, # Mark COVID-19 working days sd=True # Consider six-day work week ) print(f"Tomorrow's status (detailed): {result_detailed}") finally: await calendar.close() asyncio.run(check_tomorrow()) ``` -------------------------------- ### Check Specific Date Status with Parameters - Python Source: https://context7.com/kobylinskii-m/isdayoff/llms.txt Queries the status of a specific date, such as a holiday or working day, using the ProdCalendar client. Allows for specifying the date and passing optional parameters like locale and flags for shortened days, COVID-19 adjustments, and six-day work weeks. ```python import asyncio from datetime import date from isdayoff import ProdCalendar, DateType calendar = ProdCalendar(locale='us') async def check_date(): try: # Check New Year's Day 2024 new_year = await calendar.date(date(2024, 1, 1)) print(f"January 1, 2024: {new_year}") # Check with additional parameters aug_25 = await calendar.date( date(2021, 8, 25), locale='ru', pre=True, covid=False, sd=False ) if aug_25 == DateType.WORKING: print("August 25, 2021 was a working day") else: print("August 25, 2021 was a day off") finally: await calendar.close() asyncio.run(check_date()) ``` -------------------------------- ### Check Today's Date Status - Python Source: https://context7.com/kobylinskii-m/isdayoff/llms.txt Checks the status of the current day (working, holiday, shortened, or special COVID-19 working day) using the ProdCalendar client. Includes error handling for the API request. The `DateType` enum is used to interpret the results. ```python import asyncio from isdayoff import ProdCalendar, DateType calendar = ProdCalendar(locale='ru') async def check_today(): try: result = await calendar.today() if result == DateType.WORKING: print("Today is a working day") elif result == DateType.NOT_WORKING: print("Today is a holiday/weekend") elif result == DateType.SHORTENED: print("Today is a shortened working day") elif result == DateType.WORKING_DAY: print("Today is a special working day (COVID-19 adjustment)") except Exception as e: print(f"Error: {e}") finally: await calendar.close() asyncio.run(check_today()) ``` -------------------------------- ### Check if it's a Leap Year (Python) Source: https://github.com/kobylinskii-m/isdayoff/blob/master/README.md This Python snippet determines if a given date falls within a leap year using the isdayoff library. It takes a `date` object as input. The function returns a boolean value indicating whether the year of the provided date is a leap year. ```python await calendar.is_leap(date(2021, 1, 1)) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.