from datetime import datetime, timezone, timedelta
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build

hkt = timezone(timedelta(hours=8))
today = datetime.now(hkt).date()

# 下周一：今天如果是周三，下周一就是 +5天（7月28日）
# 但用户说下周一，从 7月23日（周三）算：下周一是 7月27日（周日）？还是 7月28日（周一）？
# 按中国人习惯"下周一"指本周一之后的那个周一，即 7月28日
days_until_monday = (7 - today.weekday()) % 7
next_monday = today + timedelta(days=days_until_monday if days_until_monday else 7)
print(f"今天: {today}, 下周一: {next_monday}")

# 7月30日：假设是今年7月30日
july_30 = datetime(today.year, 7, 30).date()
if july_30 < today:
    july_30 = datetime(today.year + 1, 7, 30).date()
print(f"7月30日: {july_30}")

# 设置两个日程
creds = Credentials.from_authorized_user_file('/root/.hermes/google_token.json',
                                               scopes=['https://www.googleapis.com/auth/calendar'])
service = build('calendar', 'v3', credentials=creds)

# 1. 下周一 16:00 前找石勃要材料
start1 = datetime(next_monday.year, next_monday.month, next_monday.day, 15, 0, tzinfo=hkt)
end1 = datetime(next_monday.year, next_monday.month, next_monday.day, 15, 30, tzinfo=hkt)
event1 = {
    'summary': '找石勃要双方各自上报2个方案的材料',
    'description': '下周一16:00前完成',
    'start': {'dateTime': start1.isoformat(), 'timeZone': 'Asia/Hong_Kong'},
    'end': {'dateTime': end1.isoformat(), 'timeZone': 'Asia/Hong_Kong'},
    'reminders': {'useDefault': True},
}
result1 = service.events().insert(calendarId='primary', body=event1).execute()
print(f"✅ {start1.strftime('%m-%d %H:%M')}-{end1.strftime('%H:%M')} | {event1['summary']}")

# 2. 7月30日检查一季度跑步奖励使用完毕
start2 = datetime(july_30.year, july_30.month, july_30.day, 9, 0, tzinfo=hkt)
end2 = datetime(july_30.year, july_30.month, july_30.day, 9, 30, tzinfo=hkt)
event2 = {
    'summary': '检查一季度跑步奖励使用完毕',
    'description': '检查一季度跑步奖励是否已使用完毕',
    'start': {'dateTime': start2.isoformat(), 'timeZone': 'Asia/Hong_Kong'},
    'end': {'dateTime': end2.isoformat(), 'timeZone': 'Asia/Hong_Kong'},
    'reminders': {'useDefault': True},
}
result2 = service.events().insert(calendarId='primary', body=event2).execute()
print(f"✅ {start2.strftime('%m-%d %H:%M')}-{end2.strftime('%H:%M')} | {event2['summary']}")
