#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
North Leeds monthly events → narrative → save as HTML file.
Usage:
export LEEDS_INSPIRED_KEY=xxxxxxxx
export MONTH=2025-08 # optional; defaults to current month
export AREAS="Chapel Allerton,Headingley,Meanwood,Moortown,Roundhay"
python3 north_leeds_events_html.py
"""
import os, sys, html, re, requests
from datetime import date
from urllib.parse import urlencode
LEEDS_API_BASE = "https://www.leedsinspired.co.uk/1.0"
ATTRIBUTION_HTML = (
'{title} '
f'({place}) ')
areas_html = ", ".join([f"{html.escape(a.strip())}" for a in areas_csv.split(",")])
intro = (
f"
'
'Listings via Leeds Inspired. '
'Please check with venues for the latest details. '
'
Here’s a quick look at what’s happening around {areas_html} this {month_label}. " f"We sifted {total_count} listings and picked a handful that feel distinctly North Leeds.
" ) return ( f"North Leeds: What’s Happening – {month_label}
" + intro + "- " + "\n".join(bullets) + "
Got a community event to share? Let us know and we’ll include it next time.
" ) def main(): key = env("LEEDS_INSPIRED_KEY") if not key: print("ERROR: Set LEEDS_INSPIRED_KEY", file=sys.stderr) sys.exit(1) iso_month = env("MONTH") start, end = month_bounds(iso_month) month_label = start.strftime("%B %Y") areas_csv = env("AREAS", "Chapel Allerton,Headingley,Meanwood,Moortown,Roundhay") items = fetch_events(key, start, end) north = filter_north(items, areas_csv) highlights = pick_highlights(north) html_body = make_story_html(month_label, areas_csv, highlights, len(north) or len(items)) out = f"north_leeds_whats_on_{start.strftime('%Y_%m')}.html" with open(out, "w", encoding="utf-8") as f: f.write(html_body) print(f"Generated: {out}") if __name__ == "__main__": main()
Add comment
Comments
Test