How to use the stravalib.model.LoadableEntity function in stravalib

To help you get started, we’ve selected a few stravalib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hozn / stravalib / stravalib / model.py View on Github external
http://strava.github.io/api/partner/v3/events/
    """
    OBJECT_TYPE_ACTIVITY = 'activity'
    ASPECT_TYPE_CREATE = 'create'

    VERIFY_TOKEN_DEFAULT = 'STRAVA'

    application_id = Attribute(int)
    object_type = Attribute(six.text_type)
    aspect_type = Attribute(six.text_type)
    callback_url = Attribute(six.text_type)
    created_at = TimestampAttribute()
    updated_at = TimestampAttribute()


class SubscriptionCallback(LoadableEntity):
    """
    Represents a Webhook Event Subscription Callback.
    """
    hub_mode = Attribute(six.text_type)
    hub_verify_token = Attribute(six.text_type)
    hub_challenge = Attribute(six.text_type)

    def validate(self, verify_token=Subscription.VERIFY_TOKEN_DEFAULT):
        assert self.hub_verify_token == verify_token


class SubscriptionUpdate(LoadableEntity):
    """
    Represents a Webhook Event Subscription Update.
    """
    subscription_id = Attribute(int)
github hozn / stravalib / stravalib / model.py View on Github external
on the units used in this object, just the binning of values).
    """
    distance = Attribute(float, units=uh.meters)  #: Distance for this split
    elapsed_time = TimeIntervalAttribute()  #: :class:`datetime.timedelta` of elapsed time for split
    elevation_difference = Attribute(float, units=uh.meters)   #: Elevation difference for split
    moving_time = TimeIntervalAttribute()  #: :class:`datetime.timedelta` of moving time for split
    average_heartrate = Attribute(float)   #: Average HR for split
    split = Attribute(int)  #: Which split number
    pace_zone = Attribute(int)  #: (undocumented)
    average_speed = Attribute(float, units=uh.meters_per_second)

    def __repr__(self):
        return ''.format(self.split, self.distance, self.elapsed_time)


class SegmentExplorerResult(LoadableEntity):
    """
    Represents a segment result from the segment explorer feature.

    (These are not full segment objects, but the segment object can be fetched
    via the 'segment' property of this object.)
    """
    _segment = None
    id = Attribute(int)  #: ID of the segment.
    name = Attribute(six.text_type)  #: Name of the segment
    climb_category = Attribute(int)  #: Climb category for the segment (0 is higher)
    climb_category_desc = Attribute(six.text_type)  #: Climb category text
    avg_grade = Attribute(float)  #: Average grade for segment.
    start_latlng = LocationAttribute()  #: Start lat/lon for segment
    end_latlng = LocationAttribute()  #: End lat/lon for segment
    elev_difference = Attribute(float, units=uh.meters)  #: Total elevation difference over segment.
    distance = Attribute(float, units=uh.meters)  #: Distance of segment.
github hozn / stravalib / stravalib / model.py View on Github external
return k in self.entries

    def __getitem__(self, k):
        return self.entries[k]


class DistributionBucket(BaseEntity):
    """
    A single distribution bucket object, used for activity zones.
    """
    max = Attribute(int)  #: Max datatpoint
    min = Attribute(int)  #: Min datapoint
    time = Attribute(int, units=uh.seconds)  #: Time in seconds (*not* a :class:`datetime.timedelta`)


class BaseActivityZone(LoadableEntity):
    """
    Base class for activity zones.

    A collection of :class:`stravalib.model.DistributionBucket` objects.
    """
    distribution_buckets = EntityCollection(DistributionBucket, (SUMMARY, DETAILED))  #: The collection of :class:`stravalib.model.DistributionBucket` objects
    type = Attribute(six.text_type, (SUMMARY, DETAILED))  #: Type of activity zone (heartrate, power, pace).
    sensor_based = Attribute(bool, (SUMMARY, DETAILED))  #: Whether zone data is sensor-based (as opposed to calculated)

    @classmethod
    def deserialize(cls, v, bind_client=None):
        """
        Creates a new object based on serialized (dict) struct.
        """
        if v is None:
            return None
github hozn / stravalib / stravalib / model.py View on Github external
class BestEffort(BaseEffort):
    """
    Class representing a best effort (e.g. best time for 5k)
    """


class SegmentEffort(BaseEffort):
    """
    Class representing a best effort on a particular segment.
    """
    hidden = Attribute(bool, (SUMMARY, DETAILED,))  # indicates a hidden/non-important effort when returned as part of an activity, value may change over time.
    device_watts = Attribute(bool, (SUMMARY, DETAILED))  #: True if the watts are from a power meter, false if estimated


class Activity(LoadableEntity):
    """
    Represents an activity (ride, run, etc.).
    """
    # "Constants" for types of activities
    RIDE = "Ride"
    RUN = "Run"
    SWIM = "Swim"
    HIKE = "Hike"
    WALK = "Walk"

    ALPINESKI = "AlpineSki"
    BACKCOUNTRYSKI = "BackcountrySki"
    CANOEING = "Canoeing"
    CROSSCOUNTRYSKIING = "CrossCountrySkiing"
    CROSSFIT = "Crossfit"
    EBIKERIDE = "EBikeRide"
github hozn / stravalib / stravalib / model.py View on Github external
use_primary_photo = Attribute(bool,(META, SUMMARY, DETAILED))  #: (undocumented)


class ActivityPhotoMeta(BaseEntity):
    """
    The photos structure returned with the activity, not to be confused with the full loaded photos for an activity.
    """
    count = Attribute(int, (META, SUMMARY, DETAILED))
    primary = EntityAttribute(ActivityPhotoPrimary, (META, SUMMARY, DETAILED))
    use_primary_photo = Attribute(bool, (META, SUMMARY, DETAILED))

    def __repr__(self):
        return '<{0} count={1}>'.format(self.__class__.__name__, self.count)


class ActivityPhoto(LoadableEntity):
    """
    A full photo record attached to an activity.
    """
    athlete_id = Attribute(int, (META, SUMMARY, DETAILED))  #: ID of athlete
    activity_id = Attribute(int, (META, SUMMARY, DETAILED))  #: ID of activity
    activity_name = Attribute(six.text_type, (META, SUMMARY, DETAILED))  #: Name of activity.
    ref = Attribute(six.text_type, (META, SUMMARY, DETAILED))  #: ref eg. "http://instagram.com/p/eAvA-tir85/"

    uid = Attribute(six.text_type, (META, SUMMARY, DETAILED))  #: unique id for instagram photo
    unique_id = Attribute(six.text_type, (META, SUMMARY, DETAILED))  #: unique id for strava photos

    caption = Attribute(six.text_type, (META, SUMMARY, DETAILED))  #: caption on photo
    type = Attribute(six.text_type, (META, SUMMARY, DETAILED))  #: type of photo (currently only InstagramPhoto)
    uploaded_at = TimestampAttribute((SUMMARY, DETAILED))  #: :class:`datetime.datetime` when was photo uploaded
    created_at = TimestampAttribute((SUMMARY, DETAILED))  #: :class:`datetime.datetime` when was photo created
    created_at_local = TimestampAttribute((SUMMARY, DETAILED))  #: :class:`datetime.datetime` when was photo created
github hozn / stravalib / stravalib / model.py View on Github external
return self._followers

    @property
    def stats(self):
        """
        :return: Associated :class:`stravalib.model.AthleteStats`
        """
        if not self.is_authenticated_athlete():
            raise exc.NotAuthenticatedAthlete("Statistics are only available for the authenticated athlete")
        if self._stats is None:
            self.assert_bind_client()
            self._stats = self.bind_client.get_athlete_stats(self.id)
        return self._stats


class ActivityComment(LoadableEntity):
    """
    Comments attached to an activity.
    """
    activity_id = Attribute(int, (META, SUMMARY, DETAILED))  #: ID of activity
    text = Attribute(six.text_type, (META, SUMMARY, DETAILED))  #: Text of comment
    created_at = TimestampAttribute((SUMMARY, DETAILED))  #: :class:`datetime.datetime` when was coment created
    athlete = EntityAttribute(Athlete, (SUMMARY, DETAILED))  #: Associated :class:`stravalib.model.Athlete` (summary-level representation)


class ActivityPhotoPrimary(LoadableEntity):
    """
    A primary photo attached to an activity (different structure from full photo record)
    """
    id = Attribute(int, (META, SUMMARY, DETAILED))  #: ID of photo, if external.
    unique_id = Attribute(six.text_type, (META, SUMMARY, DETAILED))  #: ID of photo, if internal.
    urls = Attribute(dict, (META, SUMMARY, DETAILED))
github hozn / stravalib / stravalib / model.py View on Github external
profile = Attribute(six.text_type, (SUMMARY, DETAILED))  #: URL to a 124x124 pixel profile picture
    city = Attribute(six.text_type, (SUMMARY, DETAILED))  #: Athlete's home city
    state = Attribute(six.text_type, (SUMMARY, DETAILED))  #: Athlete's home state
    country = Attribute(six.text_type, (SUMMARY, DETAILED))  #: Athlete's home country
    sex = Attribute(six.text_type, (SUMMARY, DETAILED))  #: Athlete's sex ('M', 'F' or null)
    friend = Attribute(six.text_type, (SUMMARY, DETAILED))  #: 'pending', 'accepted', 'blocked' or 'null' the authenticated athlete's following status of this athlete
    follower = Attribute(six.text_type, (SUMMARY, DETAILED))  #: 'pending', 'accepted', 'blocked' or 'null' this athlete's following status of the authenticated athlete
    premium = Attribute(bool, (SUMMARY, DETAILED))  #: Whether athlete is a premium member (true/false)

    created_at = TimestampAttribute((SUMMARY, DETAILED))  #: :class:`datetime.datetime` when athlete record was created.
    updated_at = TimestampAttribute((SUMMARY, DETAILED))  #: :class:`datetime.datetime` when athlete record was last updated.

    approve_followers = Attribute(bool, (SUMMARY, DETAILED))  #: Whether athlete has elected to approve followers


class ActivityLap(LoadableEntity):

    name = Attribute(six.text_type, (SUMMARY, DETAILED))  #: Name of lap
    activity = EntityAttribute("Activity", (SUMMARY, DETAILED))  #: The associated :class:`stravalib.model.Activity`
    athlete = EntityAttribute(Athlete, (SUMMARY, DETAILED))  #: The associated :class:`stravalib.model.Athlete`

    elapsed_time = TimeIntervalAttribute((SUMMARY, DETAILED))  #: :class:`datetime.timedelta` of elapsed time for lap
    moving_time = TimeIntervalAttribute((SUMMARY, DETAILED))  #: :class:`datetime.timedelta` of moving time for lap
    start_date = TimestampAttribute((SUMMARY, DETAILED))  #: :class:`datetime.datetime` when lap was started in GMT
    start_date_local = TimestampAttribute((SUMMARY, DETAILED), tzinfo=None)  #: :class:`datetime.datetime` when lap was started local
    distance = Attribute(float, (SUMMARY, DETAILED), units=uh.meters)  #: The distance for this lap.
    start_index = Attribute(int, (SUMMARY, DETAILED))  #:
    end_index = Attribute(int, (SUMMARY, DETAILED))  #:
    total_elevation_gain = Attribute(float, (SUMMARY, DETAILED,), units=uh.meters)  #: What is total elevation gain for lap
    average_speed = Attribute(float, (SUMMARY, DETAILED,), units=uh.meters_per_second)  #: Average speed for lap
    max_speed = Attribute(float, (SUMMARY, DETAILED,), units=uh.meters_per_second)  #: Max speed for lap
    average_cadence = Attribute(float, (SUMMARY, DETAILED,))  #: Average cadence for lap
github hozn / stravalib / stravalib / model.py View on Github external
"""
    name = Attribute(six.text_type, (SUMMARY, DETAILED))  #: Name of the route.
    description = Attribute(six.text_type, (SUMMARY, DETAILED,))  #: Description of the route.
    athlete = EntityAttribute(Athlete, (SUMMARY, DETAILED))  #: The associated :class:`stravalib.model.Athlete` that performed this activity.
    distance = Attribute(float, (SUMMARY, DETAILED), units=uh.meters)  #: The distance for the route.
    elevation_gain = Attribute(float, (SUMMARY, DETAILED), units=uh.meters)  #: Total elevation gain for the route.
    map = EntityAttribute(Map, (SUMMARY, DETAILED)) #: :class:`stravalib.model.Map` object for route.
    type = Attribute(six.text_type, (SUMMARY, DETAILED))  #: Activity type of route (1 for ride, 2 for run).
    sub_type = Attribute(six.text_type, (SUMMARY, DETAILED))  #: Activity sub-type of route (1 for road (ride and run), 2 for mtb, 3 for cx, 4 for trail, 5 for mixed).
    private = Attribute(bool, (SUMMARY, DETAILED))  #: Whether the route is private.
    starred = Attribute(bool, (SUMMARY, DETAILED))  #: Whether the route is starred.
    timestamp = Attribute(int, (SUMMARY, DETAILED))  #: Unix timestamp when route was last updated.
    # segments = NOT IMPLEMENTED


class Subscription(LoadableEntity):
    """
    Represents a Webhook Event Subscription.

    http://strava.github.io/api/partner/v3/events/
    """
    OBJECT_TYPE_ACTIVITY = 'activity'
    ASPECT_TYPE_CREATE = 'create'

    VERIFY_TOKEN_DEFAULT = 'STRAVA'

    application_id = Attribute(int)
    object_type = Attribute(six.text_type)
    aspect_type = Attribute(six.text_type)
    callback_url = Attribute(six.text_type)
    created_at = TimestampAttribute()
    updated_at = TimestampAttribute()
github hozn / stravalib / stravalib / model.py View on Github external
updated_at = TimestampAttribute()


class SubscriptionCallback(LoadableEntity):
    """
    Represents a Webhook Event Subscription Callback.
    """
    hub_mode = Attribute(six.text_type)
    hub_verify_token = Attribute(six.text_type)
    hub_challenge = Attribute(six.text_type)

    def validate(self, verify_token=Subscription.VERIFY_TOKEN_DEFAULT):
        assert self.hub_verify_token == verify_token


class SubscriptionUpdate(LoadableEntity):
    """
    Represents a Webhook Event Subscription Update.
    """
    subscription_id = Attribute(int)
    owner_id = Attribute(int)
    object_id = Attribute(int)
    object_type = Attribute(six.text_type)
    aspect_type = Attribute(six.text_type)
    event_time = TimestampAttribute()
    updates = Attribute(dict)
github hozn / stravalib / stravalib / model.py View on Github external
"""
    effort_count = Attribute(int)  #: (UNDOCUMENTED) Presumably how many efforts current athlete has on segment.
    pr_elapsed_time = TimeIntervalAttribute() #: (UNDOCUMENTED) Presumably PR elapsed time for segment.
    pr_date = DateAttribute()  #: (UNDOCUMENTED) Presumably date of PR :)

class AthletePrEffort(IdentifiableEntity):
    """
    An undocumented structure being returned for segment Athlete Pr Effort.
    """
    distance = Attribute(float, (SUMMARY, DETAILED), units=uh.meters)
    elapsed_time = TimeIntervalAttribute((SUMMARY, DETAILED))
    start_date = TimestampAttribute((SUMMARY, DETAILED))
    start_date_local = TimestampAttribute((SUMMARY, DETAILED))
    is_kom = Attribute(bool, (SUMMARY, DETAILED))

class Segment(LoadableEntity):
    """
    Represents a single Strava segment.
    """
    _leaderboard = None

    name = Attribute(six.text_type, (SUMMARY, DETAILED))  #: Name of the segment.
    activity_type = Attribute(six.text_type, (SUMMARY, DETAILED))  #: Activity type of segment ('Ride' or 'Run')
    distance = Attribute(float, (SUMMARY, DETAILED), units=uh.meters)  #: Distance of segment
    average_grade = Attribute(float, (SUMMARY, DETAILED))  #: Average grade (%) for segment
    maximum_grade = Attribute(float, (SUMMARY, DETAILED))  #: Maximum grade (%) for segment
    elevation_high = Attribute(float, (SUMMARY, DETAILED), units=uh.meters)  #: The highest point of the segment.
    elevation_low = Attribute(float, (SUMMARY, DETAILED), units=uh.meters)  #: The lowest point of the segment.
    start_latlng = LocationAttribute((SUMMARY, DETAILED))  #: The start lat/lon (:class:`tuple`)
    end_latlng = LocationAttribute((SUMMARY, DETAILED))  #: The end lat/lon (:class:`tuple`)
    start_latitude = Attribute(float, (SUMMARY, DETAILED))  #: The start latitude (:class:`float`)
    end_latitude = Attribute(float, (SUMMARY, DETAILED))  #: The end latitude (:class:`float`)