- Notifications
You must be signed in to change notification settings - Fork0
A Python package for generating calendar links and ICS files for various calendar services including Google Calendar, Apple Calendar, Yahoo Calendar, AOL Calendar, and Microsoft 365.
License
Nneji123/calendar-link
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A Python package for generating calendar links and ICS files for various calendar services including Google Calendar, Apple Calendar, Yahoo Calendar, AOL Calendar, and Microsoft 365.
- Generate calendar links for multiple services:
- Google Calendar
- Apple Calendar
- Yahoo Calendar
- AOL Calendar
- Microsoft Outlook
- Microsoft 365
- Generate ICS (iCalendar) files
- Support for timezone handling
- Event validation and sanitization
- Comprehensive error handling
pip install calendar-link
fromdatetimeimportdatetimefromcalendar_linkimportCalendarEvent,CalendarGenerator# Create an eventevent=CalendarEvent(title="Team Meeting",start_time=datetime(2024,1,15,10,0),# 10:00 AMend_time=datetime(2024,1,15,11,0),# 11:00 AMdescription="Weekly team sync meeting",location="Conference Room A",attendees=["john@example.com","jane@example.com"])# Generate calendar linksgenerator=CalendarGenerator()# Generate Google Calendar linkgoogle_link=generator.generate_link(event,"google")print(f"Google Calendar:{google_link}")# Generate ICS file contentics_content=generator.generate_ics(event)print(f"ICS Content:\n{ics_content}")# Generate all links at onceall_links=generator.generate_all_links(event)forservice,linkinall_links.items():print(f"{service}:{link}")
fromcalendar_linkimportCalendarEventevent_data= {"title":"Birthday Party","start_time":"2024-02-15T18:00:00","end_time":"2024-02-15T22:00:00","description":"Come celebrate!","location":"My House","all_day":False}event=CalendarEvent.from_dict(event_data)
importpytzfromdatetimeimportdatetimefromcalendar_linkimportCalendarEvent# Create event with specific timezoneny_tz=pytz.timezone("America/New_York")start_time=ny_tz.localize(datetime(2024,1,15,10,0))event=CalendarEvent(title="Meeting",start_time=start_time,end_time=start_time.replace(hour=11),timezone="America/New_York")
fromdatetimeimportdatetimefromcalendar_linkimportCalendarEventevent=CalendarEvent(title="Vacation Day",start_time=datetime(2024,1,15,0,0),end_time=datetime(2024,1,15,0,0),all_day=True)
fromcalendar_linkimportCalendarEvent,CalendarGeneratorevent=CalendarEvent(title="Important Meeting",start_time=datetime(2024,1,15,14,30),end_time=datetime(2024,1,15,15,30),description="Don't forget to prepare the presentation")generator=CalendarGenerator()ics_content=generator.generate_ics(event)# Save to filewithopen("meeting.ics","w")asf:f.write(ics_content)
The main class for representing calendar events.
CalendarEvent(title:str,start_time:datetime,end_time:Optional[datetime]=None,description:Optional[str]=None,location:Optional[str]=None,attendees:Optional[List[str]]=None,all_day:bool=False,timezone:Optional[str]=None)
from_dict(data: dict) -> CalendarEvent: Create event from dictionaryto_dict() -> dict: Convert event to dictionaryget_duration_minutes() -> int: Get event duration in minutesis_same_day() -> bool: Check if start and end are on same day
The main class for generating calendar links and ICS files.
generate_link(event: CalendarEvent, service: str) -> str: Generate link for specific servicegenerate_ics(event: CalendarEvent) -> str: Generate ICS file contentgenerate_all_links(event: CalendarEvent) -> Dict[str, str]: Generate all linksget_supported_services() -> Dict[str, str]: Get list of supported services
google: Google Calendarapple: Apple Calendaryahoo: Yahoo Calendaraol: AOL Calendaroutlook: Microsoft Outlookoffice365: Microsoft 365ics: ICS File
The package includes custom exceptions for better error handling:
fromcalendar_linkimportCalendarLinkError,InvalidEventDataError,UnsupportedCalendarServiceErrortry:event=CalendarEvent(title="",start_time=datetime.now())# Invalid titleexceptInvalidEventDataErrorase:print(f"Invalid event data:{e}")try:generator.generate_link(event,"unsupported_service")exceptUnsupportedCalendarServiceErrorase:print(f"Unsupported service:{e}")
The package also includes utility functions for common operations:
fromcalendar_link.utilsimportparse_datetime,validate_email,sanitize_text# Parse datetime with timezonedt=parse_datetime("2024-01-15 10:00:00","America/New_York")# Validate emailis_valid=validate_email("user@example.com")# Sanitize text for calendar servicesclean_text=sanitize_text("Event\nDescription\nwith\nnewlines")
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- ical - Python iCalendar implementation
- python-dateutil - Date utilities
- pytz - Timezone handling
About
A Python package for generating calendar links and ICS files for various calendar services including Google Calendar, Apple Calendar, Yahoo Calendar, AOL Calendar, and Microsoft 365.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.