#! /usr/bin/env python
-"""Arguments is a list of SQL paterns (will get wrapped in wildcards, %),
-display uid email and name
+"""finduser [flags] pattern...
+
+Flags:
+ -1 Print just email
+ -f Also print the comment
+
+Arguments is a list of SQL paterns (will get wrapped in wildcards, %),
+by default display full information as CSV.
"""
import mysql.connector
import datetime, os, re, subprocess, sys, string, random
+import getopt
dbconfig = {
- 'user': 'license',
- 'password': open('rwpass.txt').read().strip(),
+ 'user': 'licensereader',
+ 'password': open('ropass.txt').read().strip(),
'database': 'license'
}
conn = mysql.connector.connect(**dbconfig)
cursor = conn.cursor()
-raw = open("request-approval.txt").read()
-# Get dict of matching users
-for email in sys.argv[1:]:
- q = ('SELECT uid,reply, email,name FROM users'
- ' WHERE email LIKE %s ORDER BY uid')
+single = 0
+full = 0
+try:
+ opts, args = getopt.getopt(sys.argv[1:], "1f")
+except:
+ print __doc__
+ raise SystemExit
+
+for o,a in opts:
+ if o == '-1':
+ single = 1
+ elif o == '-f':
+ full = 1
+
+q = ('SELECT users.uid,email,reply,name,count(log.uid),comment FROM users'
+ ' LEFT JOIN log ON log.uid = users.uid'
+ ' WHERE email like %s GROUP BY email' )
+for email in args:
pat = '%' + email + '%'
cursor.execute(q, (pat,))
for row in cursor:
- uid,reply,email,name = row
- if reply == None: reply = '-'
- print uid, reply, email, name
+ uid,email,reply,name,count,comment = row
+ if reply == None:
+ reply = '-'
+ if single:
+ print email
+ else:
+ print '%d, %s, %s, %d, "%s"' % (uid, email, reply, count, name)
+ if full:
+ print '# ', comment