---
type: "Source File"
title: "!/usr/bin/env python3"
description: "#!/usr/bin/env python3 \"\"\"Strip HTML tags from article titles and fix slugs.\"\"\" import sqlite3, re DB = \"/home/ben/infra/copecheck/data/copecheck.db\" c = sqlite3.connect(DB) c.row_factory = sqlite3.Row def."
resource: "https://www.copecheck.com"
tags: ["copecheck", "main", "source-file", "py"]
timestamp: "2026-05-09T21:41:16Z"
site: "main"
source_path: "copecheck/fix_html_titles.py"
---

# !/usr/bin/env python3

Source path: `copecheck/fix_html_titles.py`  
Index snapshot generated: `2026-11-24T13:42:54Z`  
File modified: `2026-05-09T21:41:16Z`

```py
#!/usr/bin/env python3
"""Strip HTML tags from article titles and fix slugs."""
import sqlite3, re

DB = "/home/ben/infra/copecheck/data/copecheck.db"
c = sqlite3.connect(DB)
c.row_factory = sqlite3.Row

def strip_html(text):
    return re.sub(r'<[^>]+>', '', text)

def make_slug(title):
    """Reproduce the slug generation logic."""
    slug = title.lower()
    slug = re.sub(r'[^a-z0-9\s-]', '', slug)
    slug = re.sub(r'[\s-]+', '-', slug).strip('-')
    return slug[:80]

rows = c.execute("SELECT id, title, slug FROM articles WHERE title LIKE '%<%'").fetchall()
print(f"Found {len(rows)} articles with HTML tags")

fixed = 0
for r in rows:
    clean_title = strip_html(r['title'])
    if clean_title != r['title']:
        # Regenerate slug from clean title, but keep the hash suffix if present
        old_slug = r['slug']
        # Extract hash suffix (last 8 chars after last -)
        parts = old_slug.rsplit('-', 1)
        if len(parts) == 2 and len(parts[1]) == 8:
            hash_suffix = parts[1]
            new_base = make_slug(clean_title)
            new_slug = f"{new_base[:71]}-{hash_suffix}"
        else:
            new_slug = make_slug(clean_title)
        
        c.execute("UPDATE articles SET title=?, slug=? WHERE id=?", (clean_title, new_slug, r['id']))
        fixed += 1
        if fixed <= 5:
            print(f"  Fixed: {clean_title[:80]}")
            print(f"    Old slug: {old_slug}")
            print(f"    New slug: {new_slug}")

c.commit()
c.close()
print(f"\nFixed {fixed} articles")
```
