from google.oauth2.credentials import Credentials from googleapiclient.discovery import build import json cal_id = "fd0c7cf8ec9fc8fc1d8a9811c439717f6246e2e53ee9fe2046c720b29242fc4e@group.calendar.google.com" token_file = "/root/.hermes/google_token.json" with open(token_file) as f: token_data = json.load(f) service = build("calendar", "v3", credentials=Credentials.from_authorized_user_info(token_data)) events = service.events().list( calendarId=cal_id, timeMin="2026-11-01T00:00:00Z", timeMax="2026-12-10T23:59:59Z", singleEvents=True ).execute().get("items", []) print(f"Total events to process: {len(events)}") micro_weight_text = "\n\nCơ cấu đánh giá môn Kinh tế học vi mô 1:\n• Tham gia trên lớp: 10%\n• Nghiên cứu tình huống: 15% (2 bài, mỗi bài 7.5%)\n• Bài tập về nhà: 25% (2 bài, mỗi bài 12.5%)\n• Kiểm tra tại lớp (Quiz): 25%\n• Bài thi cuối kỳ: 25%" macro_weight_text = "\n\nCơ cấu đánh giá môn Kinh tế học vĩ mô:\n• Tham dự lớp và thảo luận: 20%\n• Bài kiểm tra nhanh (4 Quiz): 10% (mỗi bài 2.5%)\n• Bài tập về nhà (4 bài): 20% (mỗi bài 5%)\n• Bài thi giữa kỳ: 20%\n• Bài thi cuối kỳ: 30%" for e in events: eid = e["id"] old_summary = e.get("summary", "") old_desc = e.get("description", "") new_summary = old_summary new_desc = old_desc # 1. Shorten prefixes if new_summary.startswith("[FSPPM PA]"): new_summary = "[PA]" + new_summary[len("[FSPPM PA]"):] elif new_summary.startswith("[FSPPM]"): new_summary = "[GE]" + new_summary[len("[FSPPM]"):] elif new_summary.startswith("[DEADLINE]"): new_summary = "[DDL]" + new_summary[len("[DEADLINE]"):] # Shorten specific inner titles if needed new_summary = new_summary.replace("Nộp bài viết Tình huống", "Nộp Tình huống") # 2. Enrich weight in descriptions # Check if Micro 1 if "Micro 1" in new_summary or "Kinh tế học vi mô 1" in old_desc: if "[DDL]" in new_summary: if "Tình huống 1" in new_summary or "Tình huống 2" in new_summary: weight_note = "\nTrọng số: 7.5% tổng điểm môn học (1 trong 2 bài tình huống, tổng 15%)." if "Trọng số:" not in new_desc: new_desc += weight_note elif "Bài tập 1" in new_summary or "Bài tập 2" in new_summary: weight_note = "\nTrọng số: 12.5% tổng điểm môn học (1 trong 2 bài tập, tổng 25%)." if "Trọng số:" not in new_desc: new_desc += weight_note else: if "Cơ cấu đánh giá môn Kinh tế học vi mô 1" not in new_desc: new_desc += micro_weight_text # Check if Macro elif "Macro" in new_summary or "Kinh tế học vĩ mô" in old_desc: if "[DDL]" in new_summary: weight_note = "\nTrọng số: 5% tổng điểm môn học (1 trong 4 bài tập, tổng 20%)." if "Trọng số: 5%" not in new_desc: new_desc += weight_note else: if "Cơ cấu đánh giá môn Kinh tế học vĩ mô" not in new_desc: new_desc += macro_weight_text # Perform update if changed if new_summary != old_summary or new_desc != old_desc: print(f"Updating {eid}:") print(f" Summary: '{old_summary}' -> '{new_summary}'") service.events().patch(calendarId=cal_id, eventId=eid, body={ "summary": new_summary, "description": new_desc }).execute() print("\nAll calendar events successfully updated with shortened prefixes and detailed grade weights!")