/
DieNice
/
sync-outlook-google-events
Обзор
Документация
Войти
/
DieNice
/
sync-outlook-google-events
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
src/script_by_ai.py
65 строк
2 KB
Proskurin.DA
WIP
12 окт 2025, 16:03
12 окт 2025, 16:03
3bca496
Код
Авторство
О чём код?
from __future__ import print_function import os from io import BytesIO import httplib2 from apiclient import discovery from googleapiclient.http import MediaIoBaseUpload from oauth2client import client, tools from oauth2client.file import Storage try: import argparse flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args() except ImportError: flags = None SCOPES = "https://www.googleapis.com/auth/calendar" CLIENT_SECRET_FILE = "client_secret.json" APPLICATION_NAME = "ICS Importer" def get_credentials(): home_dir = os.path.expanduser("~") credential_dir = os.path.join(home_dir, ".credentials") if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, "calendar-ics-import.json") store = Storage(credential_path) credentials = store.get() if not credentials or credentials.invalid: flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES) flow.user_agent = APPLICATION_NAME if flags: credentials = tools.run_flow(flow, store, flags) else: credentials = tools.run(flow, store) print("Storing credentials to " + credential_path) return credentials def upload_calendar(calendar_id, calendar_file): credentials = get_credentials() http = credentials.authorize(httplib2.Http()) service = discovery.build("calendar", "v3", http=http) # Чтение содержимого файла with open(calendar_file, "rb") as f: media_body = MediaIoBaseUpload( BytesIO(f.read()), mimetype="text/calendar", resumable=True ) request = service.calendars().importEvents( calendarId=calendar_id, media_body=media_body ) response = request.execute() print(response) if __name__ == "__main__": calendar_id = "your.calendar.id@gmail.com" # Ваш ID календаря calendar_file = "path/to/your/file.ics" # Полный путь к вашему файлу .ics upload_calendar(calendar_id, calendar_file)