Skip to content
Snippets Groups Projects

Statshunters badges naar GPX POIs

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Ted Kruijff

    This script downloads the POIs from Statshunters and creates a GPX file you can load into your Garmin

    Edited
    badges-to-gpx.py 1.55 KiB
    #!/usr/bin/env python3
    
    import datetime
    import sys
    
    import requests
    
    
    def main() -> None:
    
        r = requests.get("https://www.statshunters.com/api/badges")
        r.raise_for_status()
        
        pois = []
    
        minlat = 10000
        maxlat = -10000
        minlon = 10000
        maxlon = -10000
    
        for poi in r.json().get('badges', []):
            if "coor" in poi.keys() and poi["coor"]:
                pois.append({
                    "name": poi["name"],
                    "cmt": poi["info"],
                    "coord": poi["coor"]
                })
    
                try:
                    lon, lat = poi["coor"]
                except Exception as e:
                    print(e)
                    print(poi)
    
                minlat = min(lat, minlat)
                maxlat = max(lat, maxlat)
                minlon = min(lon, minlon)
                maxlon = max(lon, maxlon)
    
        
        with open("badges.gpx", "w") as f:
            
            f.write(f"""
            <?xml version="1.0" encoding="UTF-8"?>
    <gpx version="1.0" creator="KPN" xmlns="http://www.topografix.com/GPX/1/0">
      <time>{datetime.datetime.now(tz=datetime.timezone.utc).isoformat()}</time>
      <bounds minlat="{minlat}" minlon="{minlon}" maxlat="{maxlat}" maxlon="{maxlon}"/>
    """.strip())
    
            for poi in pois:
    
                poi["name"] = poi["name"].replace("&", "&amp;")
    
                f.write(f"""
    
      <wpt lat="{poi["coord"][1]}" lon="{poi["coord"][0]}">
        <name>{poi["name"]}</name>
        <cmt>{poi["cmt"]}</cmt>
        <desc>{poi["cmt"]}</desc>
      </wpt>
    
    
                """.strip())
    
                f.write("\n")
    
    
            f.write("\n</gpx>")
    
    
    if __name__ == "__main__":
        main()
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment