mirror of
https://github.com/b4tman/sync_ics2gcal
synced 2025-01-21 23:38:58 +00:00
type annotations - scripts
This commit is contained in:
parent
e5064eeaed
commit
9dab3c5709
@ -1,5 +1,6 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import logging.config
|
import logging.config
|
||||||
|
from typing import Optional, Dict, Any
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
@ -70,7 +71,7 @@ def parse_args():
|
|||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
def load_config():
|
def load_config() -> Optional[Dict[str, Any]]:
|
||||||
result = None
|
result = None
|
||||||
try:
|
try:
|
||||||
with open('config.yml', 'r', encoding='utf-8') as f:
|
with open('config.yml', 'r', encoding='utf-8') as f:
|
||||||
@ -81,7 +82,7 @@ def load_config():
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def list_calendars(service, show_hidden, show_deleted):
|
def list_calendars(service, show_hidden: bool, show_deleted: bool) -> None:
|
||||||
fields = 'nextPageToken,items(id,summary)'
|
fields = 'nextPageToken,items(id,summary)'
|
||||||
calendars = []
|
calendars = []
|
||||||
page_token = None
|
page_token = None
|
||||||
@ -100,7 +101,7 @@ def list_calendars(service, show_hidden, show_deleted):
|
|||||||
print('{summary}: {id}'.format_map(calendar))
|
print('{summary}: {id}'.format_map(calendar))
|
||||||
|
|
||||||
|
|
||||||
def create_calendar(service, summary, timezone, public):
|
def create_calendar(service, summary: str, timezone: str, public: bool) -> None:
|
||||||
calendar = GoogleCalendar(service, None)
|
calendar = GoogleCalendar(service, None)
|
||||||
calendar.create(summary, timezone)
|
calendar.create(summary, timezone)
|
||||||
if public:
|
if public:
|
||||||
@ -108,33 +109,33 @@ def create_calendar(service, summary, timezone, public):
|
|||||||
print('{}: {}'.format(summary, calendar.calendarId))
|
print('{}: {}'.format(summary, calendar.calendarId))
|
||||||
|
|
||||||
|
|
||||||
def add_owner(service, id, owner_email):
|
def add_owner(service, calendar_id: str, owner_email: str) -> None:
|
||||||
calendar = GoogleCalendar(service, id)
|
calendar = GoogleCalendar(service, calendar_id)
|
||||||
calendar.add_owner(owner_email)
|
calendar.add_owner(owner_email)
|
||||||
print('to {} added owner: {}'.format(id, owner_email))
|
print('to {} added owner: {}'.format(calendar_id, owner_email))
|
||||||
|
|
||||||
|
|
||||||
def remove_calendar(service, id):
|
def remove_calendar(service, calendar_id: str) -> None:
|
||||||
calendar = GoogleCalendar(service, id)
|
calendar = GoogleCalendar(service, calendar_id)
|
||||||
calendar.delete()
|
calendar.delete()
|
||||||
print('removed: {}'.format(id))
|
print('removed: {}'.format(calendar_id))
|
||||||
|
|
||||||
|
|
||||||
def rename_calendar(service, id, summary):
|
def rename_calendar(service, calendar_id: str, summary: str) -> None:
|
||||||
calendar = {'summary': summary}
|
calendar = {'summary': summary}
|
||||||
service.calendars().patch(body=calendar, calendarId=id).execute()
|
service.calendars().patch(body=calendar, calendarId=calendar_id).execute()
|
||||||
print('{}: {}'.format(summary, id))
|
print('{}: {}'.format(summary, calendar_id))
|
||||||
|
|
||||||
|
|
||||||
def get_calendar_property(service, id, property):
|
def get_calendar_property(service, calendar_id: str, property_name: str) -> None:
|
||||||
response = service.calendarList().get(calendarId=id,
|
response = service.calendarList().get(calendarId=calendar_id,
|
||||||
fields=property).execute()
|
fields=property_name).execute()
|
||||||
print(response.get(property))
|
print(response.get(property_name))
|
||||||
|
|
||||||
|
|
||||||
def set_calendar_property(service, id, property, property_value):
|
def set_calendar_property(service, calendar_id: str, property_name: str, property_value: str) -> None:
|
||||||
body = {property: property_value}
|
body = {property_name: property_value}
|
||||||
response = service.calendarList().patch(body=body, calendarId=id).execute()
|
response = service.calendarList().patch(body=body, calendarId=calendar_id).execute()
|
||||||
print(response)
|
print(response)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
from typing import Dict, Any
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
@ -12,14 +14,13 @@ from . import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def load_config():
|
def load_config() -> Dict[str, Any]:
|
||||||
with open('config.yml', 'r', encoding='utf-8') as f:
|
with open('config.yml', 'r', encoding='utf-8') as f:
|
||||||
result = yaml.safe_load(f)
|
result = yaml.safe_load(f)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_start_date(date_str):
|
def get_start_date(date_str: str) -> datetime.datetime:
|
||||||
result = datetime.datetime(1, 1, 1)
|
|
||||||
if 'now' == date_str:
|
if 'now' == date_str:
|
||||||
result = datetime.datetime.utcnow()
|
result = datetime.datetime.utcnow()
|
||||||
else:
|
else:
|
||||||
@ -33,8 +34,8 @@ def main():
|
|||||||
if 'logging' in config:
|
if 'logging' in config:
|
||||||
logging.config.dictConfig(config['logging'])
|
logging.config.dictConfig(config['logging'])
|
||||||
|
|
||||||
calendarId = config['calendar']['google_id']
|
calendarId: str = config['calendar']['google_id']
|
||||||
ics_filepath = config['calendar']['source']
|
ics_filepath: str = config['calendar']['source']
|
||||||
|
|
||||||
start = get_start_date(config['start_from'])
|
start = get_start_date(config['start_from'])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user