---
type: "Source File"
title: "\"\"\"Add top 10 best/worst cities articles to CopeCheck Cities.\"\"\""
description: "\"\"\"Add top 10 best/worst cities articles to CopeCheck Cities.\"\"\" import os # 1. Create article template template_path = \"/home/ben/infra/copecheck-cities/templates/article.html\" template = r'''{% extends \"base.html\" %}."
resource: "https://cities.copecheck.com"
tags: ["copecheck", "cities", "source-file", "py"]
timestamp: "2026-05-09T15:11:11Z"
site: "cities"
source_path: "copecheck-cities/add_articles.py"
---

# """Add top 10 best/worst cities articles to CopeCheck Cities."""

Source path: `copecheck-cities/add_articles.py`  
Index snapshot generated: `2026-11-24T13:27:52Z`  
File modified: `2026-05-09T15:11:11Z`

```py
"""Add top 10 best/worst cities articles to CopeCheck Cities."""

import os

# 1. Create article template
template_path = "/home/ben/infra/copecheck-cities/templates/article.html"
template = r'''{% extends "base.html" %}

{% block title %}{{ title }} — CopeCheck Cities{% endblock %}

{% block content %}
<h1>{{ title }}</h1>
<p class="subtitle" style="color: #888; margin-bottom: 2rem;">{{ subtitle }}</p>

<div style="margin-bottom: 2rem; padding: 1.2rem; background: #111; border: 1px solid #1a1a1a; border-radius: 6px;">
    <p style="color: #ccc; font-size: 0.95rem; line-height: 1.7;">{{ intro }}</p>
</div>

{% for entry in cities %}
<div style="margin-bottom: 2.5rem; padding: 1.5rem; background: #0a0a0a; border: 1px solid #1a1a1a; border-radius: 8px;">
    <div style="display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem;">
        <span style="font-size: 2rem; font-weight: bold; color: {% if article_type == 'best' %}#22c55e{% else %}#ef4444{% endif %};">#{{ loop.index }}</span>
        <div>
            <h2 style="margin: 0; font-size: 1.3rem;">
                <a href="/{{ entry.country_code }}/{{ entry.slug }}" style="color: #f5f5f5; text-decoration: none;">
                    {{ entry.flag }} {{ entry.name }}, {{ entry.country_name }}
                </a>
            </h2>
            <span style="color: #888; font-size: 0.85rem;">Score: {{ entry.score }}/100 · Population: {{ "{:,}".format(entry.population) }}</span>
        </div>
    </div>
    <p style="color: #ccc; line-height: 1.7; margin-bottom: 0.8rem;">{{ entry.commentary }}</p>
    <div style="display: flex; gap: 1rem; flex-wrap: wrap;">
        {% for s in entry.top_sectors %}
        <span style="background: #1a1a1a; padding: 0.3rem 0.7rem; border-radius: 4px; font-size: 0.8rem; color: #aaa;">
            {{ s.label }}: {{ s.pct }}%
        </span>
        {% endfor %}
    </div>
</div>
{% endfor %}

<div style="margin-top: 2rem; padding: 1.2rem; background: #111; border: 1px solid #1a1a1a; border-radius: 6px;">
    <h2 style="font-size: 1rem;">Methodology</h2>
    <p style="color: #888; font-size: 0.85rem; margin-top: 0.5rem;">
        Rankings are based on CopeCheck's vulnerability index, which scores cities 0–100 using sector employment
        shares weighted by Frey & Osborne automation probabilities. {{ 'Lower' if article_type == 'best' else 'Higher' }}
        scores indicate {{ 'greater natural protection' if article_type == 'best' else 'greater exposure' }}
        to AI-driven workforce displacement. Data sources: ONS (UK), BLS (US), CSO (Ireland),
        Statistics Canada, ABS (Australia), Stats NZ (New Zealand).
    </p>
</div>

<div style="margin-top: 2rem;">
    <h2 style="font-size: 1.1rem;">More from the Oracle</h2>
    <ul style="list-style: none; padding: 0;">
        {% if article_type == 'best' %}
        <li style="margin-bottom: 0.5rem;"><a href="/articles/top-10-worst-cities-ai-transition" style="color: #ef4444;">Top 10 Worst Cities for the AI Transition →</a></li>
        {% else %}
        <li style="margin-bottom: 0.5rem;"><a href="/articles/top-10-best-cities-ai-transition" style="color: #22c55e;">Top 10 Best Cities for the AI Transition →</a></li>
        {% endif %}
    </ul>
</div>
{% endblock %}
'''

with open(template_path, "w") as f:
    f.write(template)
print("OK: created article.html template")

# 2. Create articles index template
index_path = "/home/ben/infra/copecheck-cities/templates/articles_index.html"
index_template = r'''{% extends "base.html" %}

{% block title %}Articles from the Oracle — CopeCheck Cities{% endblock %}

{% block content %}
<h1>Articles from the Oracle</h1>
<p class="subtitle" style="color: #888; margin-bottom: 2rem;">Analysis and rankings from across the CopeCheck Cities network.</p>

{% for article in articles %}
<a href="{{ article.url }}" style="text-decoration: none; color: inherit;">
    <div style="margin-bottom: 1.5rem; padding: 1.2rem; background: #0a0a0a; border: 1px solid #1a1a1a; border-radius: 8px; transition: border-color 0.2s;" onmouseover="this.style.borderColor='#333'" onmouseout="this.style.borderColor='#1a1a1a'">
        <h2 style="margin: 0 0 0.5rem 0; font-size: 1.15rem; color: #f5f5f5;">{{ article.title }}</h2>
        <p style="color: #888; font-size: 0.9rem; margin: 0;">{{ article.description }}</p>
    </div>
</a>
{% endfor %}
{% endblock %}
'''

with open(index_path, "w") as f:
    f.write(index_template)
print("OK: created articles_index.html template")

# 3. Patch app.py to add article routes
app_path = "/home/ben/infra/copecheck-cities/app.py"
with open(app_path, "r") as f:
    content = f.read()

# Add before the sitemap route
article_code = '''

ARTICLES = [
    {"url": "/articles/top-10-best-cities-ai-transition", "title": "Top 10 Best Cities for the AI Transition", "description": "Which cities across 6 countries are best positioned to weather AI-driven workforce displacement?"},
    {"url": "/articles/top-10-worst-cities-ai-transition", "title": "Top 10 Worst Cities for the AI Transition", "description": "The cities most vulnerable to automation across the CopeCheck network — and why their economic structures are a liability."},
]


@app.route("/articles/")
def articles_index():
    return render_template("articles_index.html", articles=ARTICLES,
        meta_description="Analysis and rankings from the CopeCheck Cities oracle.")


def _get_all_cities_ranked():
    """Load all cities from all countries, compute scores, return sorted."""
    all_cities = []
    for code, info in COUNTRIES.items():
        cities = load_country_data(code)
        for c in cities:
            c["country_code"] = code
            c["country_name"] = info["name"]
            c["flag"] = info["flag"]
            top3 = sorted(c["sectors"].items(), key=lambda x: x[1], reverse=True)[:3]
            c["top_sectors"] = [{"label": SECTOR_LABELS.get(s[0], s[0]), "pct": s[1]} for s in top3]
        all_cities.extend(cities)
    all_cities.sort(key=lambda c: c["score"])
    return all_cities


@app.route("/articles/top-10-best-cities-ai-transition")
def article_best():
    all_cities = _get_all_cities_ranked()
    best = all_cities[:10]
    for c in best:
        hr = sum(v for k, v in c["sectors"].items() if k in ["administrative_support","retail","manufacturing","financial_services","transport_storage"])
        low = sum(v for k, v in c["sectors"].items() if k in ["health","education","public_admin"])
        c["commentary"] = (
            f"With a vulnerability score of just {c['score']}/100, {c['name']} stands out for its "
            f"concentration in harder-to-automate sectors. {low:.1f}% of employment sits in health, "
            f"education, and public administration — sectors where human judgement, physical presence, "
            f"and institutional inertia provide genuine insulation from near-term AI displacement. "
            f"Only {hr:.1f}% of the workforce is in high-risk automation categories. "
            f"This does not mean {c['name']} is immune to change — it means the change arrives "
            f"more slowly, and the city has more time to adapt than most."
        )
    return render_template("article.html",
        title="Top 10 Best Cities for the AI Transition",
        subtitle="The cities best positioned to weather AI-driven workforce displacement across 6 countries.",
        intro="Not every city is equally exposed to the AI wave. Some have workforce compositions that naturally resist automation — heavy concentrations in healthcare, education, public administration, and sectors where human presence is structurally required. These are the 10 cities across the CopeCheck network with the lowest vulnerability scores. Being 'best positioned' does not mean safe. It means these cities have more runway before the displacement hits at scale.",
        cities=best,
        article_type="best",
        meta_description="The 10 cities best positioned for AI transition across UK, US, Ireland, Canada, Australia, and New Zealand.")


@app.route("/articles/top-10-worst-cities-ai-transition")
def article_worst():
    all_cities = _get_all_cities_ranked()
    worst = all_cities[-10:][::-1]
    for c in worst:
        hr = sum(v for k, v in c["sectors"].items() if k in ["administrative_support","retail","manufacturing","financial_services","transport_storage"])
        c["commentary"] = (
            f"{c['name']} scores {c['score']}/100 on the vulnerability index, placing it among the "
            f"most exposed cities in the network. A combined {hr:.1f}% of employment sits in "
            f"high-risk automation categories — retail, admin, manufacturing, financial services, "
            f"and transport. These are not sectors facing gradual erosion. They are sectors where "
            f"AI and robotics adoption is accelerating on corporate timelines, not government ones. "
            f"The structural challenge for {c['name']} is that the jobs most likely to disappear "
            f"are also the ones that currently define what the city is for."
        )
    return render_template("article.html",
        title="Top 10 Worst Cities for the AI Transition",
        subtitle="The cities most vulnerable to AI-driven workforce displacement — and why their economic structures are a liability.",
        intro="Some cities have built their economies on exactly the sectors that AI is best equipped to disrupt. High concentrations of retail, administrative support, manufacturing, financial services, and logistics create a compounding vulnerability — not just one sector at risk, but the entire employment base. These are the 10 cities across the CopeCheck network with the highest vulnerability scores. The question is not whether these cities will be affected, but whether anyone in charge is preparing for what comes next.",
        cities=worst,
        article_type="worst",
        meta_description="The 10 cities most vulnerable to AI displacement across UK, US, Ireland, Canada, Australia, and New Zealand.")

'''

# Insert before @app.route("/sitemap.xml")
marker = '@app.route("/sitemap.xml")'
if marker in content:
    content = content.replace(marker, article_code + "\n" + marker)
    with open(app_path, "w") as f:
        f.write(content)
    print("OK: added article routes to app.py")
else:
    print("ERROR: could not find sitemap marker")
```
