Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20 support writing ticks and climbs to aurora #26

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To download the climb database for a given board:

`boardlib database <board_name> <database_path>`

This will download a [sqlite](https://www.sqlite.org/index.html) database file to the given path and synchronize it with the latest available data. The database contains all of the publicly available climb data. Only the synchronization will be attempted if there is already a database at the given path,
This command will first download a [sqlite](https://www.sqlite.org/index.html) database file to the given path. After downloading, the database will then use the undocumented sync API to synchronize it with the latest available data. The database contains only the publicly available data. User data is not synchronized. If a database already exists as `database_path`, the command will skip the download step and only perform the synchronization.

NOTE: The Moonboard is not currently supported for the database command. Contributions are welcome.

Expand Down
89 changes: 80 additions & 9 deletions src/boardlib/api/aurora.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import uuid

import bs4
import requests
Expand Down Expand Up @@ -141,15 +142,6 @@ def get_climb_stats(board, token, climb_id, angle):
return response.json()


def get_climb(board, token, climb_id):
response = requests.get(
f"{API_HOSTS[board]}/v1/climbs/{climb_id}/info",
headers={"authorization": f"Bearer {token}"},
params={"angle": angle},
)
response.raise_for_status()


def get_climb_name(board, climb_id):
response = requests.get(
f"{WEB_HOSTS[board]}/climbs/{climb_id}",
Expand Down Expand Up @@ -325,3 +317,82 @@ def download_image(board, image_filename, output_filename):
response.raise_for_status()
with open(output_filename, "wb") as output_file:
output_file.write(response.content)


def generate_uuid():
return str(uuid.uuid4()).replace("-", "")


def save_ascent(
board,
token,
user_id,
climb_uuid,
angle,
is_mirror,
attempt_id,
bid_count,
quality,
difficulty,
is_benchmark,
comment,
climbed_at,
):
uuid = generate_uuid()
response = requests.put(
f"{API_HOSTS[board]}/v1/ascents/{uuid}",
headers={"authorization": f"Bearer {token}"},
json={
"user_id": user_id,
"uuid": uuid,
"climb_uuid": climb_uuid,
"angle": angle,
"is_mirror": is_mirror,
"attempt_id": attempt_id,
"bid_count": bid_count,
"quality": quality,
"difficulty": difficulty,
"is_benchmark": is_benchmark,
"comment": comment,
"climbed_at": climbed_at,
},
)
response.raise_for_status()
return response.json()


def save_climb(
board,
token,
layout_id,
setter_id,
name,
description,
is_draft,
frames,
frames_count=1,
frames_pace=0,
angle=None,
):
uuid = generate_uuid()
data = {
"uuid": uuid,
"layout_id": layout_id,
"setter_id": setter_id,
"name": name,
"description": description,
"is_draft": is_draft,
"frames_count": frames_count,
"frames_pace": frames_pace,
"frames": frames,
}
if angle:
data["angle"] = angle

response = requests.put(
f"{API_HOSTS[board]}/v2/climbs/{uuid}",
headers={"authorization": f"Bearer {token}"},
json=data,
)
response.raise_for_status()
return response.json()