---
type: "Source File"
title: "\"\"\"Import think tanks and link them to canonical policies.\"\"\""
description: "\"\"\"Import think tanks and link them to canonical policies.\"\"\" import sys, os, json, sqlite3 sys.path.insert(0, os.path.dirname(__file__)) import db def main(): # Create think_tank_policies mapping table if not exists c."
resource: "https://policy.copecheck.com"
tags: ["copecheck", "policy", "source-file", "py"]
timestamp: "2026-04-30T20:40:44Z"
site: "policy"
source_path: "copecheck-policy/import_think_tanks.py"
---

# """Import think tanks and link them to canonical policies."""

Source path: `copecheck-policy/import_think_tanks.py`  
Index snapshot generated: `2026-11-24T13:27:52Z`  
File modified: `2026-04-30T20:40:44Z`

```py
"""Import think tanks and link them to canonical policies."""
import sys, os, json, sqlite3
sys.path.insert(0, os.path.dirname(__file__))
import db

def main():
    # Create think_tank_policies mapping table if not exists
    c = db._conn()
    c.execute("""
        CREATE TABLE IF NOT EXISTS think_tank_policies (
            id INTEGER PRIMARY KEY AUTOINCREMENT,
            think_tank_slug TEXT NOT NULL,
            policy_slug TEXT NOT NULL,
            source_url TEXT,
            UNIQUE(think_tank_slug, policy_slug)
        )
    """)
    c.commit()
    
    with open(os.path.join(os.path.dirname(__file__), 'think_tanks_data.json')) as f:
        think_tanks = json.load(f)
    
    print(f"Importing {len(think_tanks)} think tanks...")
    
    for tt in think_tanks:
        db.upsert_think_tank(
            slug=tt['slug'],
            name=tt['name'],
            url=tt.get('url', ''),
            description=tt.get('description', ''),
            country=tt.get('country', 'US'),
            tier=tt.get('tier', 2),
        )
        # Update scores
        c2 = db._conn()
        c2.execute("""UPDATE think_tanks SET 
            paper_count=?, avg_cope_score=?, overall_cope_score=?
            WHERE slug=?""",
            (tt['paper_count'], tt['avg_cope_score'], tt['avg_cope_score'], tt['slug']))
        c2.commit()
        c2.close()
        
        # Link to policies
        source_urls = tt.get('source_urls', {})
        for policy_slug in tt.get('policies', []):
            c3 = db._conn()
            c3.execute("""INSERT OR REPLACE INTO think_tank_policies 
                (think_tank_slug, policy_slug, source_url) VALUES (?, ?, ?)""",
                (tt['slug'], policy_slug, source_urls.get(policy_slug, '')))
            c3.commit()
            c3.close()
        
        print(f"  {tt['name']}: avg cope {tt['avg_cope_score']}, {len(tt['policies'])} policies")
    
    print(f"\nDone! {len(think_tanks)} think tanks imported.")

if __name__ == "__main__":
    main()
```
