pR0Ps / stravaweblib

Extends the Strava v3 API using web scraping
https://pypi.python.org/pypi/stravaweblib/
25 stars 6 forks source link

Snowboarding runs and vertical #13

Open greenpasta opened 1 year ago

greenpasta commented 1 year ago

The Snowboarding activity type has "runs" (the number of times down the hill) and "vertical" fields, but they don't seem to be available in the API. I can see them in the activity on mobile, and in the training log on the web. Would this project be a suitable place to try scraping that data? I could try to put together a pull request, but just checking first if I'm barking up the right tree.

pR0Ps commented 1 year ago

It would be useful to be able to get this information, though I'm not sure how exactly it should be exposed in the WebClient API.

Maybe it could just be put in something like a top-level WebClient.get_snowboard_info function for now and refactored into ScrapingClient.get_extra_activity_details whenever I get around to finishing off #5 ? Open to suggestions.

greenpasta commented 1 year ago

I hacked around an bit, and the scraped data from the training log page is a total disaster. From my perspective a great interim solution would be if stravaweblib could just get the useful JSON from the training log page and return it as a dictionary. Then whatever I want to do with it from that point is my problem.

import json

    def get_training_log_dict(self):
        url = "{}/athletes/<ATHLETE_ID>/training/log".format(BASE_URL)
        resp = self._session.get(url, allow_redirects=False)
        if resp.status_code != 200:
            raise stravalib.exc.Fault(
                "Failed to load training log (status code: {})".format(
                    resp.status_code
                ),
            )
        soup = BeautifulSoup(resp.text, "html.parser")
        json_text = soup.find("script", {"id": "__NEXT_DATA__"}).text.strip()
        training_log_dict = json.loads(json_text)
        return training_log_dict

I assume this would only work from premium users who have access to that feature.