本文整理汇总了Python中stravalib.client.Client.get_activity方法的典型用法代码示例。如果您正苦于以下问题:Python Client.get_activity方法的具体用法?Python Client.get_activity怎么用?Python Client.get_activity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stravalib.client.Client
的用法示例。
在下文中一共展示了Client.get_activity方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_activity [as 别名]
class StravaBot:
def __init__(self):
Config = ConfigParser.ConfigParser()
Config.read("configuration/config")
Config.sections()
self.clientId = Config.get('Strava', 'ClientId')
self.clientSecret = Config.get('Strava', 'ClientSecret')
self.clientAccessToken = Config.get('Strava', 'ClientAccessToken')
self.clubId = Config.get('Strava', 'ClubId')
self.mattermostUrl = Config.get('Mattermost', 'URL')
self.delay = Config.get('Bot', 'Delay')
self.client = Client()
self.client.access_token = self.clientAccessToken
self.club = self.client.get_club(self.clubId)
self.http = urllib3.PoolManager(
cert_reqs='CERT_REQUIRED',
ca_certs=certifi.where())
print('Bot for club {name} with id {id} is here :^)\n'.format(name=self.club.name, id=self.clubId))
def post_activity(self, activity):
payload = {}
if (activity.athlete.firstname is None):
activity.athlete = self.client.get_athlete(activity.athlete.id)
first_name = activity.athlete.firstname
last_name = activity.athlete.lastname
distance = kilometers(activity.distance)
activity_duration = activity.moving_time
speed = kilometers_per_hour(activity.average_speed)
climbing = meters(activity.total_elevation_gain)
activity_id = activity.id
description = activity.name
if (len(description) > 100):
description = description[:97] + "..."
payload = {'username': 'strava_bot', 'icon_url': 'https://raw.githubusercontent.com/patoupatou/pymatterstrava/master/icon-strava.png', 'text': u':bicyclist: *{} {} : distance: {}, moving time duration: {}, speed: {}, climbing: {}* [{}](http://strava.com/activities/{}) :bicyclist:'.format(first_name, last_name, distance, activity_duration, speed, climbing, description, activity_id)}
r = self.http.request('POST', self.mattermostUrl, headers={'Content-Type': 'application/json'}, body=json.dumps(payload))
print(time.ctime() + ': New activity posted')
print('payload: ' + str(payload) + '\n')
def get_activity_details(self, activity):
return self.client.get_activity(activity.id)
def get_new_activities(self, old_activities, new_activities):
new_list = []
new_activity_ids = []
old_activity_ids = []
for new_activity in new_activities:
new_activity_ids.append(new_activity.id)
for old_activity in old_activities:
old_activity_ids.append(old_activity.id)
diff_ids = list(set(new_activity_ids) - set(old_activity_ids))
new_list = [act for act in new_activities if act.id in diff_ids]
return new_list
def run(self):
activities = set(self.client.get_club_activities(self.clubId, limit=5))
new_activities = activities
# for activity in activities:
# details = self.get_activity_details(activity)
# self.post_activity(details)
while(1):
new_activities = set(self.client.get_club_activities(self.clubId, limit=5))
diff_activities = self.get_new_activities(activities, new_activities)
if len(diff_activities) > 0:
print(time.ctime() + ': New activities!\n')
print(diff_activities)
for new_activity in diff_activities:
details = self.get_activity_details(new_activity)
self.post_activity(details)
else:
print(time.ctime() + ': No new activities\n')
activities = new_activities
time.sleep(float(self.delay))
示例2: Client
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_activity [as 别名]
client = Client(access_token=AccessToken)
athlete = client.get_athlete()
r = open('data.json', 'r')
data = json.load(r)
activities = list(d["id"] for d in data)
r.close()
stravaActivities = client.get_activities()
for activity in stravaActivities:
if (activity.id in activities):
print("Already have this activity!")
continue
a = client.get_activity(activity.id)
if (a.type != "Run"):
print("Activity was a run")
continue
print("Found a new activity!", activity.id)
act = {}
act["date"] = a.start_date_local.strftime("%y-%m-%d")
act["id"] = a.id
act["distance"] = unithelper.miles(a.distance).num
act["duration"] = a.moving_time.seconds
act["speed"] = a.average_speed.num * meterToMile * 3600
act["pace"] = float(1 / (meterToMile*a.average_speed))
act["name"] = a.name
act["splits"] = list({"time":split.elapsed_time.total_seconds() , "distance": unithelper.miles(split.distance).num } for split in a.splits_standard)
data.append(act)
示例3: elif
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_activity [as 别名]
if (act.distance > units.unit("km")(5)):
# Longer than usual. Where was I going?
pass
elif (1594398 in segments):
ret["name"] = "Morning commute"
ret["commute"] = True
elif (1547949 in segments):
ret["name"] = "Evening commute"
ret["commute"] = True
if "name" in ret and not (act.name.endswith("rit") or act.name.endswith(" Ride")):
# May already not be the default name anymore.
del ret["name"]
return ret
seen = dbm.open("seen", "c")
after = datetime.datetime.now() - datetime.timedelta(days=2)
for act in act for act in client.get_activities(after=after, limit=5):
if str(act.id) in seen:
continue
full = client.get_activity(act.id)
print full
updates = build_updates(full)
print updates
seen[str(act.id)] = "1"
if updates:
updates["activity_id"] = act.id
print client.update_activity(**updates)
示例4: list
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_activity [as 别名]
start = datetime.datetime(2016, 1, 1, 0, 0)
end = datetime.datetime(2016, 1, 3, 0, 0)
activities = client.get_activities(end, start)
STRONZO = list(activities)
types = ['time', 'latlng', 'altitude', 'heartrate', 'temp', 'segments', 'segment']
# get all streams and push efforts into array
segment_array = []
stream_types = ['time', 'latlng', 'distance', 'altitude', 'velocity_smooth', 'heartrate', 'cadence', 'watts', 'temp', 'moving', 'grade_smooth']
iterator = 0
for entry in STRONZO:
print (float(iterator) / float(len(STRONZO)))
iterator += 1
activity = client.get_activity(entry.id, True)
# stream = client.get_activity_streams(entry.id, stream_types)
# segment_array.append(stream)
if activity.segment_efforts:
for efforts in activity.segment_efforts:
# segment_activity.effort_stream = client.get_effort_streams(efforts.id, stream_types)
# segment_activity = client.get_effort_streams(efforts.id, stream_types)
# segment_activity.activity_id = activity.id
# segment_activity.effort_id = efforts.id
for leaderboard_entry in efforts.segment.leaderboard.entries:
segment_activity = client.get_effort_streams(leaderboard_entry.effort.id, stream_types)
segment_array.append({
'id': leaderboard_entry.effort.id,
'name': leaderboard_entry.athlete_name,
'streams': segment_activity
})
示例5: len
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_activity [as 别名]
activities = client.get_activities(limit=10)
assert len(list(activities)) == 10
clubs = client.get_athlete_clubs()
icc_members = client.get_club_members(club_id, limit=20)
assert len(list(icc_members)) == 20
club_activities = client.get_club_activities(club_id, limit=20)
assert len(list(club_activities)) == 20
#View activities
#for x in activities:
# print (x)
for x in clubs:
print (x)
for x in icc_members:
print (x)
for x in club_activities:
cm_activity = client.get_activity(x.id)
print (x)
print (cm_activity)
#<Activity id=270828720 name='Evening Ride' resource_state=2>
#<Activity id=270590277 name='Morning Ride' resource_state=2>
#<Activity id=270577804 name='Evening Ride' resource_state=2>
#<Activity id=270137878 name='Morning Ride' resource_state=2>
#a = client.get_activity(270137878)
示例6: str
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_activity [as 别名]
return str(s)
print 'Opening file to write...'
outputfile = open('runLogsSorted.csv', 'a') # Append the entry for each run to this file
schema = '"ID","Name","Distance (mi)","Moving time (s)","Elapsed time (s)","Elevation gain (ft)","Avg speed (mph)","Max speed (mph)","Avg cadence","Avg temp (C)","Avg HR","Max HR","Calories","Shoes","Start timestamp (local)","Start Lat","Start Lng","End Lat","End Lng","City","State","Country","Achievements","Kudos","Workout type"\n'
print 'Writing schema...'
outputfile.write(schema)
runs = 0
print 'Writing activities...'
for x in range(total_activities-1,-1,-1):
curr_activity = activity_list[x]
if curr_activity.type == 'Run':
print("Writing activity {i} (Run): {act_id}".format(i=x, act_id=curr_activity.id))
curr_activity_full = client.get_activity(curr_activity.id)
record = ''
record = record + '"' + xstr(curr_activity_full.id) + '",'
record = record + '"' + xstr(curr_activity_full.name) + '",'
record = record + '"' + xstr(unithelper.miles(curr_activity_full.distance).num) + '",'
record = record + '"' + xstr(curr_activity_full.moving_time.seconds) + '",'
record = record + '"' + xstr(curr_activity_full.elapsed_time.seconds) + '",'
record = record + '"' + xstr(unithelper.feet(curr_activity_full.total_elevation_gain).num) + '",'
record = record + '"' + xstr(unithelper.miles_per_hour(curr_activity_full.average_speed).num) + '",'
record = record + '"' + xstr(unithelper.miles_per_hour(curr_activity_full.max_speed).num) + '",'
record = record + '"' + xstr(curr_activity_full.average_cadence) + '",'
record = record + '"' + xstr(curr_activity_full.average_temp) + '",'
record = record + '"' + xstr(curr_activity_full.average_heartrate) + '",'
record = record + '"' + xstr(curr_activity_full.max_heartrate) + '",'
record = record + '"' + xstr(curr_activity_full.calories) + '",'
示例7: Client
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_activity [as 别名]
if __name__ == '__main__':
mysegments = {}
# get athlete
client = Client(access_token) # 1 -- possibly not counted
athlete = client.get_athlete() # 2
# get athlete activities
activities = client.get_activities(limit=200) # 3
print("number of activities returned", str(len(list(activities))))
# per activity, get segment efforts
for activity in activities:
segment_efforts = client.get_activity(activity.id).segment_efforts # 4
# per segment effort
for segment in segment_efforts:
mysegments[segment.segment.id] = segment.segment # save to db
# check if segment leaderboard contains any friends
for key, segment in mysegments.iteritems():
leaderboard = client.get_segment_leaderboard(key, following=True).entries # 12
# get friend with time < athlete time
for person in leaderboard:
if person.athlete_id == 1869056:
me = person
index = leaderboard.index(me)
if index > 0:
示例8: Client
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_activity [as 别名]
activity_ids = [396462307]
#391255712 - Hertford
#394259308 - Hills
#396462307 - Epping Club Ride
client = Client(access_token='250d33ceabfbe833376eb18885e797af14888512')
athlete = client.get_athlete() # Get John's full athlete record
print("Hello, {}. I know your email is {}".format(athlete.firstname, athlete.email))
# "Hello, John. I know your email is [email protected]"
activity_id = activity_ids[0] # The first ID is the root which we find the others
activity = client.get_activity(activity_id)
print (activity)
related_activities = client.get_related_activities(activity_id, limit=None)
print (related_activities)
for ra in related_activities:
print ra
activity_ids.append(ra.id)
print activity_ids
for activity_id in activity_ids:
act = client.get_activity(activity_id)
print act.name, act.type, act.athlete.firstname, act.athlete.lastname
if (act.gear == None and act.calories == None):