Skip to content

Instantly share code, notes, and snippets.

@rasher
Last active November 7, 2025 03:11
Show Gist options
  • Select an option

  • Save rasher/b4484ef63b761da0ca37a9b11fe45895 to your computer and use it in GitHub Desktop.

Select an option

Save rasher/b4484ef63b761da0ca37a9b11fe45895 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# Requirements - newer will probably work:
# intervalsicu==0.1.4
# protobuf==3.20.3
# zwift-client==0.2.0
#
# MIT License
#
# Copyright (c) 2025 Jonas Häggqvist
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import os
from datetime import date, datetime
import zwift
from zwift.profile import Profile
from intervalsicu import Intervals
def patch_zwift():
@property
def power_profile(self):
self.check_player_id()
return self.request.json('/api/power-curve/power-profile')
Profile.power_profile = power_profile
@property
def scoring_current(self):
self.check_player_id()
return self.request.json('/api/scoring/current')
Profile.scoring_current = scoring_current
def get_power_profile():
username = os.environ.get("ZWIFT_USER")
password = os.environ.get("ZWIFT_PASS")
player_id = 'me'
c = zwift.Client(username, password)
p = c.get_profile(player_id)
return p.power_profile
def get_racing_score():
username = os.environ.get("ZWIFT_USER")
password = os.environ.get("ZWIFT_PASS")
player_id = 'me'
c = zwift.Client(username, password)
p = c.get_profile(player_id)
try:
scoring = p.scoring_current
return float(p.scoring_current['scores']['ZWIFT_PUBLIC_SCORE']['value'])
except Exception as e:
return None
def put_wellness_fields(fields):
print("[{d}] {f[ZwiftzFTP]},{f[ZwiftzMAP]},{f[ZwiftVO2max]},{f[ZwiftCategory]},{f[ZwiftRacingScore]}".format(d=datetime.now(), f=fields))
athlete_id = os.environ.get('INTERVALS_ATHLETE_ID')
api_key = os.environ.get('INTERVALS_API_KEY')
today = date.today()
svc = Intervals(athlete_id, api_key, strict=False)
wellness = svc.wellness(today)
wellness.update(fields)
updated = svc.wellness_put(wellness)
if __name__ == "__main__":
from pprint import pprint
patch_zwift()
rs = get_racing_score()
pp = get_power_profile()
put_wellness_fields({
'ZwiftzFTP': pp.get('zftp'),
'ZwiftCategory': pp.get('categoryIndex'),
'ZwiftzMAP': pp.get('zmap'),
'ZwiftVO2max': pp.get('vo2max'),
'ZwiftRacingScore': rs,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment