↓ Skip to main content

XML Google Maps to OSM Plugin Migration

·3 mins

The recent spat between Garmin and Strava reminded me that there was a time when I used to post GPX files on this blog for orienteering events and my more interesting runs. I then used the XML Google Maps plugin to render those GPX files. That plugin failed to survive a PHP upgrade many years ago, and the maps were gone. I sensed another opportunity for Copilot…

This time, I decided to try Copilot in agent mode using GPT-5 mini. This was my initial prompt:

Create a script that uses the WordPress API to find all the posts on a given blog that contain a link to a file with .gpx suffix. It should then edit those posts to add a shortcode for the OSM plugin that uses the linked file in the file_list. The file needs to use a relative path.

For example, if the post on the site http://david.currie.name contained the link:

20130217 Agglestone GPX

>
> Then before this paragraph should be added the shortcode:
>
> ```
[osm_map_v3 map_center="autolat,autolon" zoom="autozoom" width="100%" height="450" file_list="../../../../wp-content/uploads/2013/02/20130217-agglestone.gpx" file_color_list="red" file_title="20130217 Agglestone GPX"]

There should be an option to not make the updates, but instead output the updates that would be made (i.e. a dry run).

You may select the programming language to use for the script.

It decided to use Python, which seemed a reasonable choice. There were only two major issues with the script it generated:

  1. It added /wp to the base URL twice. It then swallowed the error it got back, and just returned zero posts!
  2. It was trying to update the rendered content rather than the raw content.

Both of these it fixed quickly. I also got it to add a preview mode to show the content before and after changes.

The last problem, and the one that took me the longest to resolve, was really of my own creation. The eagle-eyed may have spotted that, in the original prompt, I used http in the URL. That made no difference to the generated code, but it did end up in the README. I then cut and paste that when running the script. The site is set to redirect to https, but everything becomes a GET on the redirect. This meant I was seeing a 200 back on the update POST, but nothing was getting updated!

The final script can be found here. As the README states, I’ve not attempted to tidy anything up, but it did the job for me! 82 posts were updated and their maps resurrected. For example: Run some Pubs.

Related

Lockdown 2

October started with Duncan’s birthday. It was a pretty quiet affair at home with Christine’s parents visiting and a film in the evening. Friday night has become film night more generally now (after a trial of Sky Cinema we signed up for a discounted subscription). Trying to select a film is always a bit of a trial, particularly balancing Emma’s desire for action against age-appropriate content for Duncan! I’m usually the one who ends up making a final decision to try and satisfy everyone’s needs.

Covid Cometh

·4 mins
2020 started much as 2019 had ended: with lots of activity. In the first week alone I’d done the running club’s New Year hash, the Hampshire XC Champs, and a CC6 at Badger Farm, with another one at Janesmoor two weeks later. In addition to running, there was plenty of orienteering to be had, with events at Fritham, Star Posts, Denny Wood, Mark Ash Wood, and Black Water in the first couple of months. There was also SOC and South-Central Junior Squad training to attend.

And we're back!

From time-to-time, I feel the urge to write a blog post on something and then I realise that there’s this gaping void since I last wrote anything (16 months) for which it would be remiss not to say anything given all that has happened. So, the next few posts will be a whistle-stop tour of that gap, hopefully, followed by some more regular posting. The advantage of going back over a year is that I get to relive life pre the big ‘C’ (that’s Covid, not Cancer, for those looking back at some point in the future when hopefully this is all but a distant memory).