Giter Club home page Giter Club logo

calendar-sync's Introduction

Calendar Sync

Lets you sync events from one or multiple source calendars to one target calendar very easily.

The original goal of this project was to sync events from a caldav calendar to Google Calendar. Once an early prototype was made, I wanted to make the design more flexible to use other calendars so I designed a generic Calendar Provider which is used to sync events. You can implement your own provider by implementing a concrete subclass of CalProvider.py. Already implemented are CaldavProvider.py, which can sync events from any caldav url, and GCalProvider.py, which syncs from and to Google Calendar, given credentials and a token.

How To Sync

First you have to execute pip install -r requirements.txt in order to install all requirements for caldav and the Google Calendar API.

Then syncing from one calendar to the other is very easy. You just have to create one or multiple Sync Jobs and then just sync. Here is an example which syncs all events in the next 10 days from a caldav source to the primary Google Calendar:

import datetime

from src.SyncJob import SyncJob
from src.Syncer import Syncer
from src.CaldavProvider import CaldavProvider
from src.GCalProvider import GCalProvider

if __name__ == '__main__':
    dav_provider = CaldavProvider('https://user:[email protected]/dav/calendars/')
    g_provider = GCalProvider()

    syncer = Syncer()
    syncer.register(
        SyncJob(dav_provider, g_provider, ['Private', 'Appointments', 'Work'], '[email protected]',
                datetime.datetime.today(), datetime.datetime.today() + datetime.timedelta(days=10)))
    syncer.sync()

In the case of Google Calendar, you first have to get a token and credentials. Please refer to the official Google Calendar API Documentation for further reference.

To always keep the calendars in sync I recommand setting up a VPS or Container to execute the sync every few minutes. I do this in a container using cron.

How This Works

The sync mechanism is very simple. For each day that should be synced, the program retrieves the events of this day in the source calendar. It then gets all events of this day in the target calendar, if the two are equal, then there is no further action. Otherwise all events in this day in the target calendar are deleted and are replaced by the events from the source calendar. There are surely other more efficient ways to do this, but this is very simple and works reliably.

What This Does Not Do

This program does not sync two ways. You cannot keep two calendars in sync as of today. You can take this code as a starting point and implement it yourself if you need it. It was not a priority for me.

calendar-sync's People

Contributors

alexanderbraml avatar dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.