#! /usr/bin/env python
"""Remove users (specified on commandline) who were mistakenly added.
"""

import mysql.connector, os, re, subprocess, sys
import string, random
dbconfig = {
        'user': 'license',
        'password': open('rwpass.txt').read().strip(),
        'database': 'license'
        }
conn = mysql.connector.connect(**dbconfig)
cursor = conn.cursor()

d1 = 'DELETE from log where uid = %s'
d2 = 'DELETE from users where uid = %s'
q = 'select uid from users where email = %s'
for email in sys.argv[1:]:
    cursor.execute(q, (email,))
    for uid in cursor:
        cursor.execute(d1, uid)
        cursor.execute(d2, uid)
        conn.commit()
