mysociety / caps

A simple, open database of local government climate action plan documents and emissions data.
https://cape.mysociety.org
Other
9 stars 2 forks source link

[WIP] Council climate twins page #531

Closed zarino closed 1 year ago

zarino commented 1 year ago

Fixes #530.

TODO:

Screenshot 2023-06-23 at 16-18-46 Liverpool City Council’s climate twin

ajparsons commented 1 year ago

Okay! So I've got some commits in there that make the keyphrase comparison functional.

My bigger thoughts:

ajparsons commented 1 year ago

Also the possibly unbound twin variable was bugging me because I couldn't think of a better way to do it, it turns out you can use next to grab the first one, or None if there's nothing:

twin = next(
    (
        group["councils"][0]
        for group in related_councils
        if group["type"].slug == "composite"
    ),
    None,
)

if twin in None:
    raise ValueError("No valid twin, no similar composite councils calculated")

Won't change myself because it's not necessarily more readable.