项目作者: haggaret

项目描述 :
Utility to sync events from source calendar(s) to a destination calendar
高级语言: Python
项目地址: git://github.com/haggaret/google-calendar-syncer.git
创建时间: 2019-03-17T14:38:21Z
项目社区:https://github.com/haggaret/google-calendar-syncer

开源协议:

下载


Google Calendar Syncer

Small utility to keep events from source calendar(s) updated in a destination calendar. This utility uses the Google API
to query the source calendar(s) for all events in the future and sync them to the destination calendar. It will create a
cache file for each source calendar that will be used on subsequent runs to determine what needs to be
deleted/updated/inserted. This utility can be run from the command line as follows:

  1. usage: google-calendar-syncer.py [-h] [--init] [--config CONFIG]
  2. [--src-cal-id SRC_CAL_ID]
  3. [--dst-cal-id DST_CAL_ID] [--limit LIMIT]
  4. [--profile PROFILE] [--region REGION]
  5. [--cleanup] [--verbose] [--dryrun]
  6. google-calendar-syncer
  7. optional arguments:
  8. -h, --help show this help message and exit
  9. --init Initialize - create token.json and credentials.json
  10. --config CONFIG path to config file
  11. --src-cal-id SRC_CAL_ID
  12. source cal ID
  13. --dst-cal-id DST_CAL_ID
  14. destination cal ID
  15. --limit LIMIT Limit to next X events (0)
  16. --profile PROFILE AWS Profile to use when communicating with S3
  17. --region REGION AWS region S3 bucket is in
  18. --cleanup Clean up temp folder after exection
  19. --verbose Turn on DEBUG logging
  20. --dryrun Do a dryrun - no changes will be performed
  1. Config file is a json document with the following info:
  2. ```json
  3. {
  4. "Destination Calendar 1" : {
  5. "destination_cal_id": "<destination_calendar_id>",
  6. "source_cals": {
  7. "Source Calendar Name": "<source_calendar_id>"
  8. },
  9. "exclusions": {
  10. "summary": [
  11. "Summary Exclusion Text"
  12. ]
  13. }
  14. },
  15. "Destination Calendar 2" : {
  16. "destination_cal_id" : "<destination_calendar_id>",
  17. "source_cals" :
  18. {
  19. "Source Calendar 1": "<source_calendar_id>",
  20. "Source Calendar 2": "<source_calendar_id>"
  21. }
  22. }
  23. }

examples:

using a config file:

  1. python google-calendar-syncer.py --config /path/to/config.json

supplying source and destination calendar IDs directly:

  1. python google-calendar-syncer.py --src-cal-id <source_calendar_id> --dst-cal-id <destination_calendar_id>

Note:

  • the cache folder and files (and credential files) are created relative to the working directory where the script is run from

Deploying as a scheduled lambda

If desired, this utility can also be deployed as a scheduled lambda, that will run at a given frequency.

Prerequisites

The cloudformation template that will be used to deploy the scheduled lambda does not currently create the S3 bucket
where the credential files and cache will live. That bucket should be created prior to deploying the lambda.

In addition to creating the S3 bucket, the required credential files (token.json and credentials.json) should also be
generated. This can be accomplished by running the script once manually, using the —init option. The files should be
created in the same directory that the script is run from. Once created, upload these files to the config S3 bucket.

eg.

  1. python google-calendar-syncer.py --init

Build and Deploy is accomplished using AWS SAM.

1) sam build --use-container
2) sam deploy

Note: You can create a samconfig.toml file to eliminate the need to input anything for the deploy, eg.

  1. version = 0.1
  2. [default]
  3. [default.deploy]
  4. [default.deploy.parameters]
  5. stack_name = "google-calendar-syncer"
  6. s3_bucket = "<lambda-deploy-bucket>"
  7. s3_prefix = "google-calendar-syncer"
  8. region = "<aws-region>"
  9. confirm_changeset = false
  10. capabilities = "CAPABILITY_NAMED_IAM"
  11. parameter_overrides = [
  12. "Debug=false",
  13. "UseS3=false",
  14. "UseDynamoDB=true",
  15. "Schedule='rate(10 minutes)'"
  16. ]

Running the deploy will create or update a cloudformation stack.

Note:

  • the bucket_name referenced above will likely be a different bucket than was used during the package step above
  • see here for schedule_expression values

Running using Docker (under development)

If desired, the script can be run within a Docker container (if a python environment isn’t readily available)

First build the image using the included Dockerfile

  1. docker build . -t google-calendar-syncer

Note that you will need to mount a few files into the container, namely:

  • config.json file
  • cache folder
  • credentials.json file (for google authentication)
  • token.json file (for google authentication)

Run the container:

  1. docker run -v /path/to/config.josn:/app/config.json \
  2. -v /path/to/cache:/app/cache \
  3. -v /path/to/credentials.json:/app/credentials.json \
  4. -v /path/to/token.json:/app/token.json
  5. google-calendar-syncer --config /app/config.json

At this point, the only way I’ve been able to generate the credentials.json and token.json files is by running the
script outside of the docker environment once and then mounting the files created as mentioned above.