本文整理汇总了Python中stravalib.client.Client.get_club_activities方法的典型用法代码示例。如果您正苦于以下问题:Python Client.get_club_activities方法的具体用法?Python Client.get_club_activities怎么用?Python Client.get_club_activities使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stravalib.client.Client
的用法示例。
在下文中一共展示了Client.get_club_activities方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from stravalib.client import Client [as 别名]
# 或者: from stravalib.client.Client import get_club_activities [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_club_activities [as 别名]
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]"
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)