Skip to content

Instantly share code, notes, and snippets.

@walkermatt
Last active February 10, 2026 15:29
Show Gist options
  • Select an option

  • Save walkermatt/1e3f10c4d3923e3eedc42d121d031fa9 to your computer and use it in GitHub Desktop.

Select an option

Save walkermatt/1e3f10c4d3923e3eedc42d121d031fa9 to your computer and use it in GitHub Desktop.
Script to update ol-ishare html page response body to point at a different iShare Maps server
import re
from bs4 import BeautifulSoup
from mitmproxy import ctx
from mitmproxy import http
class UpdateOliConfig:
def response(self, flow: http.HTTPFlow) -> None:
content_type = flow.response.headers.get("content-type")
# ctx.log.info(f'content_type: {content_type}')
if "text/html" in content_type:
html = BeautifulSoup(flow.response.content, "html.parser")
if html.body:
scripts = html.find_all("script")
for script in scripts:
js = script.string
if js:
# ctx.log.info(js)
ishareurl_re = r"""(iShareUrl\s*:\s*)((?:'|")[^"']*(?:'|"))"""
js = re.sub(
ishareurl_re,
"\\1'https://cy-map-v6-0-9.devops.astun.co.uk/'",
js,
0,
re.MULTILINE,
)
profile_re = r"""(profile\s*:\s*)((?:'|")[^"']*(?:'|"))"""
js = re.sub(
profile_re, "\\1'mapsources/AllMaps'", js, 0, re.MULTILINE
)
layers_re = r"(layers\s*:\s*)(\[[^\]]*\])"
js = re.sub(layers_re, "\\1['Doctors']", js, 0, re.MULTILINE)
view_re = r"(view\s*:\s*)({[^}]*})"
js = re.sub(
view_re,
"\\1{easting: 521000, northing: 161000, zoom: 100000}",
js,
0,
re.MULTILINE,
)
# ctx.log.info(js)
script.string = js
flow.response.content = str(html).encode("utf8")
addons = [UpdateOliConfig()]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment