Skip to content

Commit

Permalink
cli group for property commands
Browse files Browse the repository at this point in the history
  • Loading branch information
b4tman committed May 1, 2021
1 parent 3b0de9d commit c3bdd25
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 27 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,23 @@ wget https://raw.githubusercontent.com/b4tman/sync_ics2gcal/develop/sample-confi
### Manage calendars

```sh
manage-ics2gcal <subcommand> [-h] [options]
manage-ics2gcal GROUP | COMMAND
```

subcomands:
**GROUPS**:

* **property** - get/set properties (see [CalendarList resource](https://developers.google.com/calendar/v3/reference/calendarList#resource)), subcommands:
- **get** - get calendar property
- **set** - set calendar property

**COMMANDS**:

* **list** - list calendars
* **create** - create calendar
* **add_owner** - add owner to calendar
* **remove** - remove calendar
* **rename** - rename calendar
* **get** - get calendar property (see [CalendarList resource](https://developers.google.com/calendar/v3/reference/calendarList#resource))
* **set** - set calendar property


Use **-h** for more info.

Expand Down
54 changes: 31 additions & 23 deletions sync_ics2gcal/manage_calendars.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,36 @@ def load_config(filename: str) -> Optional[Dict[str, Any]]:
return result


class PropertyCommands:
""" get/set google calendar properties """

def __init__(self, _service):
self._service = _service

def get(self, calendar_id: str, property_name: str) -> None:
""" get calendar property
Args:
calendar_id: calendar id
property_name: property key
"""
response = self._service.calendarList().get(calendarId=calendar_id,
fields=property_name).execute()
print(response.get(property_name))

def set(self, calendar_id: str, property_name: str, property_value: str) -> None:
""" set calendar property
Args:
calendar_id: calendar id
property_name: property key
property_value: property value
"""
body = {property_name: property_value}
response = self._service.calendarList().patch(body=body, calendarId=calendar_id).execute()
print(response)


class Commands:
""" manage google calendars in service account """

Expand All @@ -31,6 +61,7 @@ def __init__(self, config: str = 'config.yml'):
if self._config is not None and 'logging' in self._config:
logging.config.dictConfig(self._config['logging'])
self._service = GoogleCalendarService.from_config(self._config)
self.property = PropertyCommands(self._service)

def list(self, show_hidden: bool = False, show_deleted: bool = False) -> None:
""" list calendars
Expand Down Expand Up @@ -104,29 +135,6 @@ def rename(self, calendar_id: str, summary: str) -> None:
self._service.calendars().patch(body=calendar, calendarId=calendar_id).execute()
print('{}: {}'.format(summary, calendar_id))

def get(self, calendar_id: str, property_name: str) -> None:
""" get calendar property
Args:
calendar_id: calendar id
property_name: property key
"""
response = self._service.calendarList().get(calendarId=calendar_id,
fields=property_name).execute()
print(response.get(property_name))

def set(self, calendar_id: str, property_name: str, property_value: str) -> None:
""" set calendar property
Args:
calendar_id: calendar id
property_name: property key
property_value: property value
"""
body = {property_name: property_value}
response = self._service.calendarList().patch(body=body, calendarId=calendar_id).execute()
print(response)


def main():
fire.Fire(Commands, name='manage-ics2gcal')
Expand Down

0 comments on commit c3bdd25

Please sign in to comment.