-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auth from ecs api + some code migration
- Loading branch information
Showing
16 changed files
with
257 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import os | ||
from typing import Dict | ||
|
||
import sib_api_v3_sdk | ||
from dotenv import load_dotenv | ||
from urllib3.exceptions import ProtocolError | ||
|
||
load_dotenv() | ||
|
||
configuration = sib_api_v3_sdk.Configuration() | ||
configuration.api_key["api-key"] = os.environ["EMAIL_API_KEY"] | ||
|
||
api_instance = sib_api_v3_sdk.TransactionalEmailsApi( | ||
sib_api_v3_sdk.ApiClient(configuration) | ||
) | ||
|
||
|
||
def send_alert_email( | ||
subject: str, | ||
text_content: str, | ||
to: Dict[str, str] = { | ||
"name": "Jamie Voynow", | ||
"email": "voynow99@gmail.com", | ||
}, | ||
sender: Dict[str, str] = { | ||
"name": "Jamie Voynow", | ||
"email": "voynowtestaddress@gmail.com", | ||
}, | ||
) -> sib_api_v3_sdk.CreateSmtpEmail: | ||
""" | ||
Generic template to send alerts/notifications to myself based on miscellaneous events | ||
""" | ||
html_content = f""" | ||
<html> | ||
<body> | ||
<h1>{subject}</h1> | ||
<p>{text_content}</p> | ||
</body> | ||
</html> | ||
""" | ||
send_smtp_email = sib_api_v3_sdk.SendSmtpEmail( | ||
to=[to], html_content=html_content, sender=sender, subject=subject | ||
) | ||
try: | ||
return api_instance.send_transac_email(send_smtp_email) | ||
except ProtocolError: | ||
return api_instance.send_transac_email(send_smtp_email) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ class StravaEvent(BaseModel): | |
object_type: str | ||
object_id: int | ||
owner_id: int | ||
event_time: int | ||
updates: dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from src import auth_manager, supabase_client | ||
from src.types.webhook import StravaEvent | ||
|
||
# from src.training_week import update_training_week | ||
# from src.types.exe_type import ExeType | ||
|
||
|
||
def handle_activity_create(event: StravaEvent) -> dict: | ||
""" | ||
Handle the creation of a Strava activity | ||
:param event: Strava webhook event | ||
""" | ||
pass | ||
# user = supabase_client.get_user(event.owner_id) | ||
# strava_client = auth_manager.get_strava_client(user.athlete_id) | ||
# activity = strava_client.get_activity(event.object_id) | ||
|
||
# if activity.sport_type == "Run": | ||
# return update_training_week( | ||
# user=user, | ||
# exe_type=ExeType.MID_WEEK, | ||
# ) | ||
# return { | ||
# "success": False, | ||
# "error": f"Unsupported activity type: {activity.sport_type}", | ||
# } | ||
|
||
|
||
def maybe_process_strava_event(event: StravaEvent) -> dict: | ||
""" | ||
Process the Strava webhook event. Perform any updates based on the event data. | ||
Strava Event: subscription_id=2****3 aspect_type='create' object_type='activity' object_id=1*********4 owner_id=9******6 event_time=1731515741 updates={} | ||
Strava Event: subscription_id=2****3 aspect_type='update' object_type='activity' object_id=1*********9 owner_id=9******6 event_time=1731515699 updates={'title': 'Best running weather ❄️'} | ||
:param event: Strava webhook event | ||
:return: Success status and error message if any | ||
""" | ||
if event.aspect_type == "create": | ||
return handle_activity_create(event) | ||
else: | ||
return { | ||
"success": False, | ||
"error": f"Unsupported event type: {event.aspect_type}", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.