Exemple #1
0
    def generate(self):
        client = Client(self._username, self._password)
        activity = client.get_activity(self._player_id)
        start_date = self._start_date

        start = 0
        done = False

        while not done:
            activities = activity.list(start=start, limit=50)

            for activity_data in activities:
                activity_id = activity_data['id']
                self._metadata[activity_id] = activity_data
                try:
                    for a in activity.get_data(activity_id):
                        if not start_date or (start_date
                                              and start_date <= a['time']):
                            a['id'] = activity_id
                            yield a['time'], pd.Series(a)
                        elif start_date:
                            done = True
                            break
                except Exception as e:
                    metadata = activity.get_activity(activity_id)
                    print('Exception: %s (%d/ Saved: %s/Duration: %s)' %
                          (e, activity_id, str(
                              metadata['lastSaveDate']), metadata['duration']))

                if done:
                    break

            if len(activities) < 50:
                done = True
            start += 50
Exemple #2
0
class TestZwift(unittest.TestCase):
    def setUp(self):
        username = '******'
        password = '******'
        self.player_id = 123456
        self.client = Client(username, password)

    def test_activity(self):
        activity = self.client.get_activity(self.player_id)
        assert isinstance(activity, Activity)
        assert activity.player_id == self.player_id

    def test_profile(self):
        profile = self.client.get_profile(self.player_id)
        assert isinstance(profile, Profile)
        assert profile.player_id == self.player_id

    def test_profile_me(self):
        profile = self.client.get_profile()
        assert isinstance(profile, Profile)
        assert profile.player_id == 'me'

    def test_world(self):
        world = self.client.get_world()
        assert isinstance(world, World)
        assert world.world_id == 1  # default world id
class ZwiftWrapper:
    def __init__(self, username, password):
        self.client = Client(username, password)
        self.profile = self.client.get_profile().profile

    def current_zone(self):
        self.update_profile_maybe()
        return self.get_zone()

    def current_heartrate(self):
        self.update_profile_maybe()
        return self.heartrate()

    def update_profile_maybe(self):
        if self.profile['worldId'] == None:
            self.profile = self.client.get_profile().profile

    def world(self):
        if self.profile['worldId'] != None:
            return self.client.get_world(self.profile['worldId'])

    def player_status(self):
        return self.world().player_status(self.profile['id'])

    def ftp(self):
        return self.profile['ftp']

    def power(self):
        return self.player_status().power

    def heartrate(self):
        rate = 45
        if self.profile['worldId'] != None:
            rate = self.player_status().heartrate
        if rate == 0:
            rate = 45
        return rate

    def get_zone(self):
        zone = 1
        if self.profile['worldId'] != None:
            zone = self.zone_from_ratio(self.power() / self.ftp())
        return zone

    def zone_from_ratio(self, ratio):
        zone = 1
        if ratio > 1.2:
            zone = 6
        elif ratio > 1.05:
            zone = 5
        elif ratio > 0.9:
            zone = 4
        elif ratio > 0.75:
            zone = 3
        elif ratio > 0.55:
            zone = 2
        return zone
Exemple #4
0
def init_zwift_client():
    """
    zwift-client 0.2.0
    """
    from zwift import Client
    from skyline import credlib
    username = credlib.zwift_username
    password = credlib.zwift_password
    zwift_id = credlib.zwift_id
    zwift = Client(username, password)

    return zwift, zwift_id
Exemple #5
0
#GPIO.output(RELAIS_4_GPIO, GPIO.LOW) # an
GPIO.output(RELAIS_4_GPIO, GPIO.HIGH)  # aus
#GPIO.output(RELAIS_3_GPIO, GPIO.LOW) # an
GPIO.output(RELAIS_3_GPIO, GPIO.HIGH)  # aus
#GPIO.output(RELAIS_2_GPIO, GPIO.LOW) # aus
GPIO.output(RELAIS_2_GPIO, GPIO.HIGH)  # aus
#GPIO.output(RELAIS_1_GPIO, GPIO.LOW) # an
GPIO.output(RELAIS_1_GPIO, GPIO.HIGH)  # aus

Herzfrequenz = 0
Herzschwelle1 = 115
Herzschwelle2 = 135
Herzschwelle3 = 155
Herz_Hyst = 2

cli = Client('email', 'pw')
world = cli.get_world()
players = world.players
friends = players['friendsInWorld']
friend = random.choice(friends)
#player_id = friend['playerId']

# find Player_id
profile = cli.get_profile()
your_player_id = profile.latest_activity['profile']['id']
player_id = your_player_id
# end find player_id

player_state = world.player_status(player_id)
print(player_state.player_state)
print(player_state.heartrate)
Exemple #6
0
#!/usr/bin/env python3

__author__ = 'Mike Walker'

import sys
import time
from zwift import Client as ZwiftClient

# Parse user creds, player_id
username = sys.argv[1]
password = sys.argv[2]
player_id = sys.argv[3]

client = ZwiftClient(username, password)
profile = client.get_profile(player_id)

# print(profile.latest_activity)

data = {}

if profile.latest_activity['profile']['riding']:
    # print('Riding')
    world = client.get_world(profile.latest_activity['profile']['worldId'])

    data.update({
        "timestamp": time.time(),
        "altitude": world.player_status(player_id).altitude,
        "cadence": world.player_status(player_id).cadence,
        "course": world.player_status(player_id).course,
        "distance": world.player_status(player_id).distance,
        "f19": world.player_status(player_id).f19,
 def __init__(self, username, password):
     self.client = Client(username, password)
     self.profile = self.client.get_profile().profile
Exemple #8
0
#!/usr/bin/env python3

__author__ = 'Mike Walker'

import sys
from zwift import Client as ZwiftClient

# Parse user creds, player_id
username = sys.argv[1]
password = sys.argv[2]
player_id = sys.argv[3]

client = ZwiftClient(username, password)
profile = client.get_profile(player_id)

print(profile.profile)
Exemple #9
0
def players(players):

    for player in players['friendsInWorld']:
        print(player)


if __name__ == "__main__":

    mqtt_client = mqtt.Client(mqtt_client_name)
    mqtt_client.username_pw_set(mqtt_login, mqtt_pw)
    mqtt_client.will_set(mqtt_topic_will, payload="Offline", retain=True)
    mqtt_client.connect(mqtt_host_name)
    mqtt_client.publish(mqtt_topic_will, payload="Online", retain=True)

    client = Client(username, password)
    world = client.get_world(1)

    #players(world.players)

    if check_online(world.players):
        last_distance = -1
        last_altitude = -1
        last_slope = 0
        avgsum_Slope = 0
        cnt_Slope = 0

        avgsum_altitude = 0
        cnt_altitude = 0
        avgsum_distance = 0
        cnt_distance = 0
Exemple #10
0
from zwift import Client
cli = Client('email', 'pw')
profile = cli.get_profile()
your_player_id = profile.latest_activity['profile']['id']
print your_player_id




Herzfrequenz=0
Geschwindigkeit=0
Leistung=0
Herzschwelle1=115
Herzschwelle2=135
Herzschwelle3=155
Herz_Hyst=2
WSpede=0
WHerz=0
player_id=1407
cli = Client('name','pw')
world = cli.get_world()
players = world.players
#friends= players['friendsInWorld']
#friend = random.choice(friends)
#player_id = friend['playerId']

# The function below is executed when someone requests a URL with the pin number and action in it:
@app.route("/<changePin>/<action>")
def action(changePin, action):
   # Convert the pin from the URL into an integer:
   changePin = int(changePin)
   # Get the device name for the pin being changed:
   deviceName = pins[changePin]['name']
   # If the action part of the URL is "on," execute the code indented below:
   if action == "on":
Exemple #12
0
#!/usr/bin/env python3

__author__ = 'Mike Walker'

import sys
from zwift import Client as ZwiftClient

# Parse user creds, player_id
username = sys.argv[1]
password = sys.argv[2]
player_id = sys.argv[3]

client = ZwiftClient(username, password)
profile = client.get_profile(player_id)
activity = client.get_activity(player_id)

if len(sys.argv) == 5:
    try:
        if int(sys.argv[4]) <= 50:
            activity_list = activity.list(limit=sys.argv[4])
            for i in activity_list:
                print(i)
        else:
            print(activity.list())
    except:
        print("Got invalid arg. Exiting")
        pass
elif len(sys.argv) == 6:
    activity_list = activity.list(start=sys.argv[4], limit=sys.argv[5])
    for i in activity_list:
        print(i)
from zwift import Client
import subprocess
timeout = 200

bulb = Bulb("192.168.0.76", auto_on=True, effect="smooth", duration=timeout) #IP Address of your bulb have to be replaced
bulb.set_brightness(50)
bulb.start_music()

#replace your Heart Rate Zone here
Herzfrequenz = 0
Herzschwelle1 = 70
Herzschwelle2 = 90
Herzschwelle3 = 100
Herz_Hyst = 2

cli = Client('YourMailAdress', 'YourPassword')
world = cli.get_world()
players = world.players
friends = players['friendsInWorld']
friend = random.choice(friends)
profile = cli.get_profile()
your_player_id = profile.latest_activity['profile']['id']
player_id = your_player_id


player_state = world.player_status(player_id)
print(player_state.player_state)
print(player_state.heartrate)
while True:
    player_state = world.player_status(player_id)
    print "Herzfrequenz =", (player_state.heartrate)
Exemple #14
0
 def setUp(self):
     username = '******'
     password = '******'
     self.player_id = 123456
     self.client = Client(username, password)