跳转到主要内容

使用网络爬虫扩展Strava v3 API

项目描述

stravaweblib

提供stravalib包的所有功能,并使用网络爬虫扩展它。

身份验证

为了登录网站,WebClient类需要电子邮件和密码,或现有会话的JWT。Strava将此JWT存储在strava_remember_tokencookie中。

客户端登录后,可以通过WebClientjwt属性访问当前会话的JWT。存储此JWT(以及来自stravalibaccess_token)允许在不再次登录的情况下恢复会话。这可以避免速率限制和锁定。

示例

from stravaweblib import WebClient

# Log in (requires API token and email/password for the site)
client = WebClient(access_token=OAUTH_TOKEN, email=EMAIL, password=PASSWORD)

# Store the current session's information
jwt = client.jwt
access_token = client.access_token

# Create a new client that continues to use the previous web session
client = WebClient(access_token=access_token, jwt=jwt)

额外功能

导出活动

以GPX、TCX或上传的原格式下载活动文件。

from stravaweblib import WebClient, DataFormat

# Log in (requires API token and email/password for the site)
client = WebClient(access_token=OAUTH_TOKEN, email=EMAIL, password=PASSWORD)

# Get the first activity id (uses the normal stravalib API)
activities = client.get_activities()
activity_id = activities.next().id

# Get the filename and data stream for the activity data
data = client.get_activity_data(activity_id, fmt=DataFormat.ORIGINAL)

# Save the activity data to disk using the server-provided filename
with open(data.filename, 'wb') as f:
    f.writelines(data.content)

删除活动

从网站删除活动。请注意,这之前可以通过API完成,但端点已在2017年1月17日删除

from stravaweblib import WebClient

# Log in (requires API token and email/password for the site)
client = WebClient(access_token=OAUTH_TOKEN, email=EMAIL, password=PASSWORD)

# Get the first activity id (uses the normal stravalib API)
activities = client.get_activities()
activity_id = activities.next().id

# Delete the activity
client.delete_activity(activity_id)

获取自行车组件

检索添加到自行车上的所有组件。可以可选地仅显示特定日期激活的组件。

from stravaweblib import WebClient
from datetime import datetime

# Log in (requires API token and email/password for the site)
client = WebClient(access_token=OAUTH_TOKEN, email=EMAIL, password=PASSWORD)

# Get a list of bikes the current user owns
athlete = client.get_athlete()
bikes = athlete.bikes

# Get the id of the first bike
bike_id = bikes.next().id

# Get all components of the first bike (past and present)
client.get_bike_components(bike_id)

# Get the current components on the first bike
client.get_bike_components(bike_id, on_date=datetime.now())

导出路线

以GPX或TCX格式下载路线文件。

from stravaweblib import WebClient, DataFormat

# Log in (requires API token and email/password for the site)
client = WebClient(access_token=OAUTH_TOKEN, email=EMAIL, password=PASSWORD)

# Get the first route id (uses the normal stravalib API)
routes = client.get_routes()
route_id = routes.next().id

# Get the filename and data stream for the activity data
data = client.get_route_data(route_id, fmt=DataFormat.GPX)

# Save the activity data to disk using the server-provided filename
with open(data.filename, 'wb') as f:
    f.writelines(data.content)

许可

根据Mozilla公共许可证,版本2.0许可

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分布

stravaweblib-0.0.8.tar.gz (7.9 kB 查看哈希值)

上传时间 源代码

构建分布

stravaweblib-0.0.8-py3-none-any.whl (7.2 kB 查看哈希值)

上传时间 Python 3

由支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面