bestdadjokes/fix.py

23 lines
981 B
Python

import sys
with open('/home/opc/REPOS/bestdadjokes/build.py', 'r') as f:
lines = f.readlines()
start_idx = 290
end_idx = 291
new_code = """ ld = [
{"@context": "https://schema.org", "@type": "BreadcrumbList", "itemListElement": [
{"@type": "ListItem", "position": 1, "name": "Home", "item": SITE_URL + '/'},
{"@type": "ListItem", "position": 2, "name": c['name'], "item": SITE_URL + '/category/%s/' % slug}]},
{"@context": "https://schema.org", "@type": "ItemList", "itemListElement": [
{"@type": "ListItem", "position": i + 1, "url": f"{SITE_URL}/#joke-{j['id']}"}
for i, j in enumerate(js)
]}
]
return layout(title, desc, body, '/category/%s/' % slug,
'<script type="application/ld+json">%s</script>' % esc(json.dumps(ld)))
"""
lines = lines[:start_idx] + [new_code] + lines[end_idx:]
with open('/home/opc/REPOS/bestdadjokes/build.py', 'w') as f:
f.writelines(lines)