使用网络爬虫扩展Strava v3 API
项目描述
stravaweblib
提供stravalib包的所有功能,并使用网络爬虫扩展它。
身份验证
为了登录网站,WebClient
类需要电子邮件和密码,或现有会话的JWT。Strava将此JWT存储在strava_remember_token
cookie中。
客户端登录后,可以通过WebClient
的jwt
属性访问当前会话的JWT。存储此JWT(以及来自stravalib
的access_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)
许可
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源代码分布
stravaweblib-0.0.8.tar.gz (7.9 kB 查看哈希值)
构建分布
stravaweblib-0.0.8-py3-none-any.whl (7.2 kB 查看哈希值)
关闭
stravaweblib-0.0.8.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 7432a19ac72c0fa0c370a01a8fe51cd90a22fb64c1627c2ca64bc960899baadb |
|
MD5 | cb9fa67ce52fbcd6b8469fa818214b7a |
|
BLAKE2b-256 | 1fe9103676f3dc0f408435ec809ec144dd3aa6085c7c15921b27448180363cf8 |
关闭
stravaweblib-0.0.8-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | ea1a7e0f2dbe83896c45209dddd556f030890464dc3d616cc838734d07fd1415 |
|
MD5 | 564aff27fed3dd4faa528a0d6af6d7d6 |
|
BLAKE2b-256 | 8d2535cb6f850c64e88162cb51b3895817ddfdd56dd9496b618bd84bfb7e1dcc |