import requests
import datetime
from dotenv import load_dotenv
import os


def get_calendar_events():
    token = os.getenv("HAS_TOKEN")
    if not token:
        raise Exception("Missing HAS token")

    headers = {"Authorization": f"Bearer {token}"}
    payload = {
        "start": datetime.datetime.now().strftime("%Y-%m-%d"),
        "end": (datetime.datetime.now() + datetime.timedelta(days=14)).strftime(
            "%Y-%m-%d"
        ),
    }
    response = requests.get(
        "https://has.nozzy.online/api/calendars/calendar.romosborne_gmail_com",
        headers=headers,
        params=payload,
    )
    return response.json()


def get_todo_items():
    token = os.getenv("HAS_TOKEN")
    if not token:
        raise Exception("Missing HAS token")
    headers = {"Authorization": f"Bearer {token}"}
    payload = {"entity_id": "todo.todo_2"}
    params = {"return_response": "null"}
    response = requests.post(
        "https://has.nozzy.online/api/services/todo/get_items",
        headers=headers,
        params=params,
        json=payload,
    )
    data = response.json()
    return data["service_response"]["todo.todo_2"]["items"]


if __name__ == "__main__":
    load_dotenv()
    events = get_todo_items()
    for item in events:
        print(item["summary"])
