mirror of
				https://github.com/b4tman/sync_ics2gcal
				synced 2025-11-04 12:38:32 +00:00 
			
		
		
		
	cli group for property commands
This commit is contained in:
		
							
								
								
									
										13
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								README.md
									
									
									
									
									
								
							@@ -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.
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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 """
 | 
			
		||||
 | 
			
		||||
@@ -31,6 +61,7 @@ class Commands:
 | 
			
		||||
        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
 | 
			
		||||
@@ -104,29 +135,6 @@ class Commands:
 | 
			
		||||
        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')
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user