import json
import csv
import io

from flask import Flask, jsonify, redirect, request

import time

import requests
from lark_oapi import Client, LogLevel, logger
from lark_oapi.api.drive.v1 import ListFileRequest
import chardet
from flask import Flask, request, jsonify
import lark_oapi as lark
from attendance import get_user_ids_and_names,get_attendance_data,save_to_csv,get_all_department_ids
from message import fetch_messages_for_chat,fetch_chats,save_messages,str_to_timestamp_seconds
from bitable import read_csv_with_auto_encoding_from_bytes,get_table_ids,extract_app_token,get_all_records
from files import list_files_recursive,extract_folder_token_from_url
from calendars import parse_event_time,format_ts,save_token,ensure_token_valid,load_token

client = lark.Client.builder() \
    .app_id("cli_a8180bd0bb6e100d") \
    .app_secret("vC0j95daj8X0wNGlNfiFtfyuhrocvfyC") \
    .log_level(lark.LogLevel.DEBUG) \
    .build()
# 获取日历列表
response = client.calendar.v4.calendar.list()
if response.code == 0:
    calendar_list = response.data.calendar_list
    print(calendar_list)

# 获取指定日历的日程列表
calendar_id = calendar_list[0]['calendar_id']
event_resp = client.calendar.v4.calendar_event.list(calendar_id=calendar_id)
if event_resp.code == 0:
    events = event_resp.data.items
    print(events)
