Skip to content

ekalvi/strava-segment-elevation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

strava-segment-elevation

A Python script to retrieve elevation and distance data for a specific Strava segment using the Strava API and export the resulting elevation profile as a CSV file.

Overview

This project fetches altitude and distance streams for a specified Strava segment and saves them in a CSV file. It is useful for analyzing or visualizing the elevation profile of a segment.

Features

  • Accepts Strava segment ID as a command-line argument.
  • Fetches altitude and distance streams for the segment.
  • Exports the elevation profile as a CSV file (elevation_profile.csv).
  • Uses environment variables (or a .env file) for secure API token management.

Prerequisites

  • Python 3.x
  • A Strava account with an API application registered to obtain your Client ID, Client Secret, and Access Token.
  • The following Python packages:
    • requests
    • python-dotenv

Installation

  1. Clone the Repository

    git clone https://github.com/your-username/strava-segment-elevation.git
    cd strava-segment-elevation
  2. Set Up a Virtual Environment (Optional)

    python -m venv venv
    source venv/bin/activate      # On Windows use: venv\Scripts\activate
  3. Install Dependencies

    pip install -r requirements.txt

    If you don’t have a requirements.txt file yet, you can install manually:

    pip install requests python-dotenv

Configuration

  1. Create a .env File
    In the project root directory, create a file named .env and add your Strava access token:

    STRAVA_ACCESS_TOKEN=your_actual_access_token_here
  2. Obtain Your Access Token
    Follow the Strava API documentation to register an application and obtain your access token.

Usage

Fetch Elevation Data for a Strava Segment

python strava_elevation.py <segment_id>

Example:

python strava_elevation.py 30408380

Specify an Output CSV File

By default, the script saves the CSV as elevation_profile.csv. To specify a different filename, use the -o option:

python strava_elevation.py 30408380 -o my_segment_data.csv

Troubleshooting

  • Environment Variable Not Found
    Ensure that the .env file is in the same directory as your script and that you have installed python-dotenv to load the environment variables.

  • API Errors
    Check your Strava access token and ensure your OAuth application has the necessary permissions.

License

This project is licensed under the MIT License.

Acknowledgments

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages