Skip to main content

How to automatically create a website with your newest komoot tour

How to automatically create a website with your newest komoot tour

This tutorial has been updated on the 22nd of December 2025 to improve the script and fix some errors.

I wanted to include a komoot tour into a website. For this use case komoot offers to embed a tour as an iframe. Since I don't feel like updating the iframe-link on the website every time there is a new tour I decided to write a small script to automate this task. There are still some details I want to improve in the future that you can find at the end of this post. But for now this script works as intended.

Prerequisite

For this tutorial you should have:
- a linux server with its own IPV4 address
- a domain name under your control

Depending on where you want to embed your iframe it might be enought to have an IPV6 address with no domain name but I haven't tested this yet.

Installing

First you have to install some packages:

sudo apt install python3 python3-pip nginx snapd
sudo snap install certbot --classic

Then install the PyPi package komootgpx. This tool is used to get a list of all your planned tours. You can install it either in a python virtual environment or system wide like I did:

pip3 install --break-system-packages komootgpx

Then add komootgpx to your PATH so you can call the command from any directory. To do this check the output from the last command. This should show you where the package was installed to. In my case it was "/home/ubuntu/.local/bin", so I added this path to /etc/environment and sourced it:

sudoedit /etc/environment
. /etc/environment

Configure HTTPS

Next up configure HTTPS for your domain so the connection between the user and the server is encrypted.

Leaving out this step might give you trouble when defining the link in the iframe (some web hosters demand an HTTPS-Link).

  1. Point your domain name to your IPV4 address
  2. Add a dummy nginx config with your domain name as the server_name. Restart nginx with sudo systemctl restart nginx.service
  3. Enable HTTPS for this domain with sudo certbot --nginx

Now you should be able to access your server over you domain name with HTTPS.

The script

Create a new file in your desired directory and change the permission:

touch my-script.sh
chmod +x my-script.sh

Then add the following content to your script:

#!/bin/bash
export PATH=$PATH:/home/ubuntu/.local/bin
export PYTHONPATH=$PYTHONPATH:/home/ubuntu/.local/lib/python3.11/site-packages

DOMAIN="your-website.example.com"
MAIL="your-komoot-mail-address@example.com"
PASSWORD="your-komoot-password"

NEW_TOUR_ID=$(komootgpx --mail=$MAIL --pass=$PASSWORD -a -t=planned -l | grep -oP '^\d+' | head -n 1)
CURRENT_TOUR_ID=$(grep -oP 'https://www\.komoot\.com/tour/\K\d+' /etc/nginx/sites-available/forward)

if [[ $NEW_TOUR_ID == $CURRENT_TOUR_ID ]]
then
    exit 0;
else
    rm /etc/nginx/sites-available/forward
    echo "server {
        server_name $DOMAIN;
        add_header Cache-Control \"no-store, no-cache\";
    if_modified_since off;
    expires off;
    etag off;
        location / {
            return 301 https://www.komoot.com/tour/$OUTPUT/embed;
        }
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/$DOMAIN/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/$DOMAIN/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
    }
server {
    if (\$host = $DOMAIN) {
        return 301 https://\$host\$request_uri;
    } # managed by Certbot
        listen 80;
        server_name $DOMAIN;
    return 404; # managed by Certbot
}" | tee /etc/nginx/sites-available/forward > /dev/null
    systemctl restart nginx.service
else
    exit 0;
fi

Don't forget to change the variables DOMAIN, MAIL and PASSWORD. Also change the two export statements at the top to point to your komootgpx and python installation directories.

This script does the following:

  1. Get ALL planned komoot tours of the specified user. Fetch the first ID (newest tour) and write it to the variable NEW_TOUR_ID.
  2. Fetch the CURRENT_TOUR_ID from your nginx config
  3. Test if those two IDs are the same. If no:
    1. Remove the current nginx config in /etc/nginx/sites-availabe/ that is called 'forward'
    2. Write a new config in the same place using your NEW_TOUR_ID
    3. Restart nginx.service
  4. If there is no new tour (so NEW_TOUR_ID is equal to CURRENT_TOUR_ID), then do nothing and exit script.

To test the script create a new komoot tour and execute the script. It should replace/create your nginx config and reload nginx. If you visit your website you now get redirected to your komoot-tour.

Cronjob

If the last step worked you can add the script as a cron job:

sudo crontab -e

Then add the following line after specifying the script's location:

15 1 * * * /home/ubuntu/my-script.sh

This executes the script at 1:15 UTC in the night every day. You can tweak this value to your likings.

Website integration

On your website add an iframe with the following content (replace the domain with your own):

<iframe src="https://my-website.example.com" width="100%" height="600" frameborder="0" scrolling="no"></iframe>

Your website now redirects you to the komoot-website of your newest tour.

To do

These are things I want to improve in my script in the future:
- [ ] Follow best practices for using sudo in a script
- [ ] Install the komootgpx package in virtual env instead of system wide
- [ ] Maybe use a more sophisticated way to find the newest tour instead of just choosing one from the last 1-2 days
- [ ] Private Tours might lead to an error because non-logged in users can't see them. Maybe there is a way to filter them.