
- Set up FastAPI application structure - Implement SQLite database with SQLAlchemy - Create WhatsApp webhook endpoints - Implement message storage and analysis - Integrate Gemini 2.5 Pro for message analysis - Add email delivery of insights - Configure APScheduler for weekend analysis - Add linting with Ruff
48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
"""
|
|
Date and time utility functions.
|
|
"""
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
def get_start_of_week(dt: datetime = None) -> datetime:
|
|
"""
|
|
Get the start of the week (Monday) for a given date.
|
|
|
|
Args:
|
|
dt: The date to get the start of the week for. Defaults to current date.
|
|
|
|
Returns:
|
|
Datetime representing the start of the week
|
|
"""
|
|
dt = dt or datetime.now()
|
|
return dt - timedelta(days=dt.weekday())
|
|
|
|
|
|
def get_end_of_week(dt: datetime = None) -> datetime:
|
|
"""
|
|
Get the end of the week (Sunday) for a given date.
|
|
|
|
Args:
|
|
dt: The date to get the end of the week for. Defaults to current date.
|
|
|
|
Returns:
|
|
Datetime representing the end of the week
|
|
"""
|
|
dt = dt or datetime.now()
|
|
return get_start_of_week(dt) + timedelta(days=6)
|
|
|
|
|
|
def get_previous_week_range() -> tuple[datetime, datetime]:
|
|
"""
|
|
Get the date range for the previous week.
|
|
|
|
Returns:
|
|
Tuple of (start_date, end_date) for the previous week
|
|
"""
|
|
today = datetime.now()
|
|
# Go back to the previous week
|
|
previous_week = today - timedelta(days=7)
|
|
start_date = get_start_of_week(previous_week)
|
|
end_date = get_end_of_week(previous_week)
|
|
return start_date, end_date
|