Add last-chance update
[omc-tools.git] / finduser
index cea3dc72995484d19558dba727acde27a5d6d216..481c04b79a02600a9219fc20ed249c49bfd3e513 100755 (executable)
--- a/finduser
+++ b/finduser
@@ -3,6 +3,7 @@
 
 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.
@@ -19,29 +20,34 @@ dbconfig = {
         }
 conn = mysql.connector.connect(**dbconfig)
 cursor = conn.cursor()
-raw = open("request-approval.txt").read()
 
 single = 0
-opts, args = getopt.getopt(sys.argv[1:], "1")
+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
-    else:
-        print __doc__
-        raise SystemExit
+    elif o == '-f':
+        full = 1
 
-# Get dict of matching users
+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:
-    q = ('SELECT users.uid,email,reply,name,count(log.uid) FROM users'
-            ' LEFT JOIN log ON log.uid = users.uid'
-            ' WHERE email like %s GROUP BY email' )
     pat = '%' + email + '%'
     cursor.execute(q, (pat,))
     for row in cursor:
-        uid,email,reply,name,count = row
+        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