Skip to content

Commit

Permalink
Fix issue where workout id is [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
gazpachoking committed Oct 26, 2021
1 parent df5ca33 commit 78f6bb8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "trainaspower"
version = "0.6.4"
version = "0.6.5"
description = "Convert TrainAsOne plans to power and upload to Final Surge for use with Stryd pod."
authors = ["Chase Sterling <[email protected]>"]
license = "MIT"
Expand Down
23 changes: 22 additions & 1 deletion trainaspower/trainasone.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ def get_next_workouts(config) -> Generator[models.Workout, None, None]:
) from exc


def decode_cloudflare_email(encoded_email):
"""
The workout id gets protected as if it was an email address by cloudflare. :eyeroll:
"""
decoded = ""
chunks = [encoded_email[i:i+2] for i in range(0, len(encoded_email), 2)]
k = int(chunks[0], 16)

for chunk in chunks[1:]:
decoded += chr(int(chunk, 16) ^ k)

return decoded


def get_workout(workout_url: str, date: datetime.date, config: models.Config) -> models.Workout:
r = tao_session.get(workout_url)
try:
Expand All @@ -64,7 +78,14 @@ def get_workout(workout_url: str, date: datetime.date, config: models.Config) ->
w = models.Workout()
w.date = date
name = workout_html.find(".summary span", first=True).text
number = workout_html.find(".summary sup", first=True).text
number_element = workout_html.find(".summary sup", first=True)
cf_email = number_element.find(".__cf_email__", first=True)
if cf_email:
number = decode_cloudflare_email(cf_email.attrs['data-cfemail'])
else:
number = number_element.text
number = number.rstrip("@")

w.duration = parse_duration(workout_html.find(".detail>span", first=True).text)
w.distance = parse_distance(workout_html.find(".detail", first=True).text)
w.id = number
Expand Down

0 comments on commit 78f6bb8

Please sign in to comment.