Step 6: Refresh static image

Each MapHub map has a static image, which is used in the following places:

  • Embed view, before the user clicks the "Play button".
  • The Download / Images links.
  • Small thumbnails on "My Maps" page.

Images can be refreshed in two ways:

  • Manually, when you save the map in the web interface.
  • When using the API, by using the Refresh map image endpoint.

The following function refreshes the map's image through the API.

def refresh_image():
    with open(MAP_DATA_JSON) as f:
        map_data = json.load(f)

    url = 'https://maphub.net/api/1/map/refresh_image'

    args = {
        'map_id': map_data['id'],
    }

    headers = {'Authorization': 'Token ' + API_KEY}

    res = requests.post(url, json=args, headers=headers)
    data = res.json()

    if 'id' not in data:
        print(data['error'])
        return

    print(data['message'])

Full script file

link