mirror of
https://github.com/b4tman/sync_ics2gcal
synced 2025-12-14 07:19:14 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
d146eec7ae
|
|||
|
3ecd6695cf
|
77
README.md
77
README.md
@@ -1,11 +1,86 @@
|
||||
# sync_ics2gcal
|
||||
|
||||
[](https://badge.fury.io/py/sync-ics2gcal)
|
||||
[](https://travis-ci.org/b4tman/sync_ics2gcal)
|
||||
[](https://dependabot.com)
|
||||
[](https://dependabot.com)
|
||||
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fb4tman%2Fsync_ics2gcal?ref=badge_shield)
|
||||

|
||||
|
||||
Python scripts for sync .ics file with Google calendar
|
||||
|
||||
## Installation
|
||||
|
||||
To install from [PyPI](https://pypi.org/project/sync-ics2gcal/) with [pip](https://pypi.python.org/pypi/pip), run:
|
||||
|
||||
```
|
||||
pip install sync-ics2gcal
|
||||
```
|
||||
|
||||
|
||||
Or download source code and install:
|
||||
|
||||
```
|
||||
python setup.py install
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
### Create application in Google API Console
|
||||
1. Create a new project: https://console.developers.google.com/project
|
||||
2. Choose the new project from the top right project dropdown (only if another project is selected)
|
||||
3. In the project Dashboard, choose "Library"
|
||||
4. Find and Enable "Google Calendar API"
|
||||
5. In the project Dashboard, choose "Credentials"
|
||||
6. In the "Service Accounts" group, click to "Manage service accounts"
|
||||
7. Click "Create service account"
|
||||
8. Choose service account name and ID
|
||||
9. Go back to "Service Accounts" group in "Credentials"
|
||||
10. Edit service account and click "Create key", choose JSON and download key file.
|
||||
|
||||
### Create working directory
|
||||
For example: `/home/user/myfolder`.
|
||||
1. Save service account key in file `service-account.json`.
|
||||
2. Download [sample config](https://github.com/b4tman/sync_ics2gcal/blob/develop/sample-config.yml) and save to file `config.yml`. For example:
|
||||
```
|
||||
wget https://raw.githubusercontent.com/b4tman/sync_ics2gcal/develop/sample-config.yml -O config.yml
|
||||
```
|
||||
3. *(Optional)* Place source `.ics` file, `my-calendar.ics` for example.
|
||||
|
||||
### Configuration parameters
|
||||
* `start_from` - start date:
|
||||
* full format datetime, `2018-04-03T13:23:25.000001Z` for example
|
||||
* or just `now`
|
||||
* *(Optional)* `service_account` - service account filename, remove it from config to use [default credentials](https://developers.google.com/identity/protocols/application-default-credentials)
|
||||
* *(Optional)* `logging` - [config](https://docs.python.org/3.8/library/logging.config.html#dictionary-schema-details) to setup logging
|
||||
* `google_id` - target google calendar id, `my-calendar@group.calendar.google.com` for example
|
||||
* `source` - source `.ics` filename, `my-calendar.ics` for example
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
### Manage calendars
|
||||
|
||||
```
|
||||
manage-ics2gcal <subcommand> [-h] [options]
|
||||
```
|
||||
|
||||
subcomands:
|
||||
* **list** - list calendars
|
||||
* **create** - create calendar
|
||||
* **add_owner** - add owner to calendar
|
||||
* **remove** - remove calendar
|
||||
* **rename** - rename calendar
|
||||
|
||||
Use **-h** for more info.
|
||||
|
||||
### Sync calendar
|
||||
|
||||
just type:
|
||||
```
|
||||
sync-ics2gcal
|
||||
```
|
||||
|
||||
|
||||
## How it works
|
||||
|
||||

|
||||
|
||||
@@ -14,6 +14,21 @@ class GoogleCalendarService():
|
||||
service Resource
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def default():
|
||||
"""make service Resource from default credentials (authorize)
|
||||
( https://developers.google.com/identity/protocols/application-default-credentials )
|
||||
( https://googleapis.dev/python/google-auth/latest/reference/google.auth.html#google.auth.default )
|
||||
|
||||
Returns:
|
||||
service Resource
|
||||
"""
|
||||
|
||||
scopes = ['https://www.googleapis.com/auth/calendar']
|
||||
credentials, _ = google.auth.default(scopes=scopes)
|
||||
service = discovery.build('calendar', 'v3', credentials=credentials)
|
||||
return service
|
||||
|
||||
@staticmethod
|
||||
def from_srv_acc_file(service_account_file):
|
||||
"""make service Resource from service account filename (authorize)
|
||||
@@ -27,6 +42,26 @@ class GoogleCalendarService():
|
||||
scoped_credentials = credentials.with_scopes(scopes)
|
||||
service = discovery.build('calendar', 'v3', credentials=scoped_credentials)
|
||||
return service
|
||||
|
||||
@staticmethod
|
||||
def from_config(config):
|
||||
"""make service Resource from config dict
|
||||
|
||||
Arguments:
|
||||
config -- dict() config with keys:
|
||||
(optional) service_account: - service account filename
|
||||
if key not in dict then default credentials will be used
|
||||
( https://developers.google.com/identity/protocols/application-default-credentials )
|
||||
|
||||
Returns:
|
||||
service Resource
|
||||
"""
|
||||
|
||||
if 'service_account' in config:
|
||||
service = GoogleCalendarService.from_srv_acc_file(config['service_account'])
|
||||
else:
|
||||
service = GoogleCalendarService.default()
|
||||
return service
|
||||
|
||||
def select_event_key(event):
|
||||
"""select event key for logging
|
||||
|
||||
@@ -86,8 +86,7 @@ def main():
|
||||
if 'logging' in config:
|
||||
logging.config.dictConfig(config['logging'])
|
||||
|
||||
srv_acc_file = config['service_account']
|
||||
service = GoogleCalendarService.from_srv_acc_file(srv_acc_file)
|
||||
service = GoogleCalendarService.from_config(config)
|
||||
|
||||
if 'list' == args.command:
|
||||
list_calendars(service)
|
||||
|
||||
@@ -34,14 +34,13 @@ def main():
|
||||
|
||||
calendarId = config['calendar']['google_id']
|
||||
ics_filepath = config['calendar']['source']
|
||||
srv_acc_file = config['service_account']
|
||||
|
||||
start = get_start_date(config['start_from'])
|
||||
|
||||
converter = CalendarConverter()
|
||||
converter.load(ics_filepath)
|
||||
|
||||
service = GoogleCalendarService.from_srv_acc_file(srv_acc_file)
|
||||
service = GoogleCalendarService.from_config(config)
|
||||
gcalendar = GoogleCalendar(service, calendarId)
|
||||
|
||||
sync = CalendarSync(gcalendar, converter)
|
||||
|
||||
Reference in New Issue
Block a user