Importing 450 new DIDs and need each to have Superfecta CallerID enabled

This post had a solution, but I found that the original code needed a small tweak to get it to work. Here is my version that is working on FreePBX 16. Just run it to have it enable Superfecta for all existing DIDs in FreePBX.

#!/usr/bin/python
import MySQLdb

db = MySQLdb.connect(host="localhost",
                     db="asterisk")

# Create a Cursor object to execute queries.
cur = db.cursor()

# Select inbound route extension that don't exist in the superfecta table
cur.execute("select extension,cidnum from incoming where extension not in (select extension from superfecta_to_incoming);")

# Loop over and insert them
for row in cur.fetchall() :
        print row[0], " ", row[1]
        sql = "INSERT INTO superfecta_to_incoming (extension, cidnum, scheme) VALUES (%s, %s, %s)"
        val = (row[0], row[1], "ALL|ALL")
        print val
        cur.execute(sql, val)

db.commit()