Skip to content

Commit

Permalink
New user row with email and preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
voynow committed Aug 21, 2024
1 parent 5e28cfe commit 646ceb3
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 15 deletions.
30 changes: 17 additions & 13 deletions src/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
)
from src.supabase_client import (
get_training_week_with_coaching,
list_users,
upsert_training_week_update,
upsert_training_week_with_coaching,
)
Expand Down Expand Up @@ -77,19 +78,22 @@ def run_update_training_week_process(


def lambda_handler(event, context):
client_preferences = "A) Training for a marathon B) This will be my second marathon C) Prefer workouts on Wednesdays and long runs on Saturdays"
sysmsg_base = f"{COACH_ROLE}\nYour client has included the following preferences: {client_preferences}\n"

# activities setup
athlete_id = os.environ["JAMIES_ATHLETE_ID"]
strava_client = get_strava_client(athlete_id)
for user in list_users():

# get current time in EST
est = timezone(timedelta(hours=-5))
datetime_now_est = datetime.now(tz=timezone.utc).astimezone(est)
strava_client = get_strava_client(user.athlete_id)
sysmsg_base = f"{COACH_ROLE}\nYour client has included the following preferences: {user.preferences}\n"

# weekday 6 is Sunday
if datetime_now_est.weekday() == 6:
run_gen_training_week_process(strava_client, sysmsg_base, athlete_id)
else:
run_update_training_week_process(strava_client, sysmsg_base, athlete_id)
# get current time in EST
est = timezone(timedelta(hours=-5))
datetime_now_est = datetime.now(tz=timezone.utc).astimezone(est)

# TODO add user.email to send_email

# weekday 6 is Sunday
if datetime_now_est.weekday() == 6:
run_gen_training_week_process(strava_client, sysmsg_base, user.athlete_id)
else:
run_update_training_week_process(
strava_client, sysmsg_base, user.athlete_id
)
25 changes: 25 additions & 0 deletions src/supabase_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from src.types.mid_week_analysis import MidWeekAnalysis
from src.types.training_week import TrainingWeekWithCoaching, TrainingWeekWithPlanning
from src.types.user_auth_row import UserAuthRow
from src.types.user_row import UserRow

load_dotenv()

Expand Down Expand Up @@ -58,6 +59,30 @@ def get_user_auth(athlete_id: int) -> UserAuthRow:
return UserAuthRow(**response.data[0])


def list_athlete_ids() -> list[int]:
"""
List all athlete_ids in the user_auth table
:return: list of athlete_ids
"""
table = client.table("user_auth")
response = table.select("athlete_id").execute()

return [row["athlete_id"] for row in response.data]


def list_users() -> list[UserRow]:
"""
List all users in the user_auth table
:return: list of UserAuthRow
"""
table = client.table("user")
response = table.select("*").execute()

return [UserRow(**row) for row in response.data]


def upsert_training_week_with_coaching(
athlete_id: int,
training_week_with_coaching: TrainingWeekWithCoaching,
Expand Down
10 changes: 10 additions & 0 deletions src/types/user_row.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from datetime import datetime

from pydantic import BaseModel


class UserRow(BaseModel):
athlete_id: int
email: str
preferences: str
created_at: datetime
27 changes: 25 additions & 2 deletions test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -12,7 +12,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -165,6 +165,29 @@
"test_mid_week_workflow()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[UserRow(athlete_id=98390356, email='voynow99@gmail.com', preferences='A) Training for a marathon B) This will be my second marathon C) Prefer workouts on Wednesdays and long runs on Saturdays', created_at=datetime.datetime(2024, 8, 21, 21, 12, 55, 723179, tzinfo=datetime.timezone.utc)),\n",
" UserRow(athlete_id=104454087, email='Rachel.decker122@gmail.com', preferences='A) Training for a marathon B) This will be my first marathon C) Generally more concerned with staying healthy and building up my long run VS doing speed workouts', created_at=datetime.datetime(2024, 8, 21, 21, 14, 35, 885680, tzinfo=datetime.timezone.utc))]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from src.supabase_client import list_users\n",
"\n",
"users = list_users()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit 646ceb3

Please sign in to comment.