1
0
mirror of https://github.com/b4tman/sync_ics2gcal synced 2024-09-21 00:48:02 +00:00

cli group for property commands

This commit is contained in:
Dmitry Belyaev 2021-05-01 17:58:30 +03:00
parent 3b0de9d636
commit c3bdd25d5a
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
2 changed files with 40 additions and 27 deletions

View File

@ -63,18 +63,23 @@ wget https://raw.githubusercontent.com/b4tman/sync_ics2gcal/develop/sample-confi
### Manage calendars ### Manage calendars
```sh ```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 * **list** - list calendars
* **create** - create calendar * **create** - create calendar
* **add_owner** - add owner to calendar * **add_owner** - add owner to calendar
* **remove** - remove calendar * **remove** - remove calendar
* **rename** - rename 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. Use **-h** for more info.

View File

@ -18,6 +18,36 @@ def load_config(filename: str) -> Optional[Dict[str, Any]]:
return result 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: class Commands:
""" manage google calendars in service account """ """ manage google calendars in service account """
@ -31,6 +61,7 @@ class Commands:
if self._config is not None and 'logging' in self._config: if self._config is not None and 'logging' in self._config:
logging.config.dictConfig(self._config['logging']) logging.config.dictConfig(self._config['logging'])
self._service = GoogleCalendarService.from_config(self._config) self._service = GoogleCalendarService.from_config(self._config)
self.property = PropertyCommands(self._service)
def list(self, show_hidden: bool = False, show_deleted: bool = False) -> None: def list(self, show_hidden: bool = False, show_deleted: bool = False) -> None:
""" list calendars """ list calendars
@ -104,29 +135,6 @@ class Commands:
self._service.calendars().patch(body=calendar, calendarId=calendar_id).execute() self._service.calendars().patch(body=calendar, calendarId=calendar_id).execute()
print('{}: {}'.format(summary, calendar_id)) 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(): def main():
fire.Fire(Commands, name='manage-ics2gcal') fire.Fire(Commands, name='manage-ics2gcal')