Add email address into COPY input
authorDan Scott <dan@coffeecode.net>
Thu, 1 Sep 2011 04:34:25 +0000 (00:34 -0400)
committerDan Scott <dscott@laurentian.ca>
Tue, 7 May 2013 18:37:55 +0000 (14:37 -0400)
Signed-off-by: Dan Scott <dscott@laurentian.ca>
tools/patron-load/ldap_sync

index 43cecce..6a8a9a6 100644 (file)
@@ -218,8 +218,7 @@ def create_staging_table():
     return """
 DROP TABLE IF EXISTS scratchpad.usr_staging;
 CREATE TABLE scratchpad.usr_staging (usrname TEXT, email TEXT, family_name TEXT, first_given_name TEXT, ident_value TEXT, lang TEXT, affiliation TEXT, profile INT, home_ou INT, status TEXT);
-COPY scratchpad.usr_staging (usrname, email, family_name, first_given_name, ident_value, lang, affiliation) FROM STDIN;
-"""
+COPY scratchpad.usr_staging (usrname, email, family_name, first_given_name, ident_value, lang, affiliation) FROM STDIN;"""
 
 def update_existing_users():
     """
@@ -341,7 +340,7 @@ def search_for_students(con, attributes, create_date):
             else:
                 # dump_data(result_data)
                 insert_into_staging(result_data)
-                print(r'\.')
+        print(r'\.')
     except ldap.LDAPError, e:
         print e
 
@@ -350,24 +349,28 @@ def insert_into_staging(result_data):
     Generate statements to push data into the staging table
     """
 
-    usrname = result_data[0][1]['cn']
-    email = result_data[0][1]['mail']
-    family_name = result_data[0][1]['sn']
-    given_name = result_data[0][1]['givenName']
-    datatel = result_data[0][1]['lulColleagueId']
+    if 'mail' not in result_data[0][1]:
+        print >> sys.stderr, 'mail not found for %s' % result_data[0][1]['cn']
+        return
+
+    usrname = result_data[0][1]['cn'][0]
+    email = result_data[0][1]['mail'][0]
+    family_name = result_data[0][1]['sn'][0]
+    given_name = result_data[0][1]['givenName'][0]
+    datatel = result_data[0][1]['lulColleagueId'][0]
 
     if 'preferredLanguage' in result_data[0][1]:
-        lang = result_data[0][1]['preferredLanguage']
+        lang = result_data[0][1]['preferredLanguage'][0]
     else:
         lang = r'\N'
 
     if 'lulPrimaryAffiliation' in result_data[0][1]:
-        affiliation = result_data[0][1]['lulPrimaryAffiliation']
+        affiliation = result_data[0][1]['lulPrimaryAffiliation'][0]
     else:
         affiliation = r'\N'
 
-    print "%s\t%s\t%s\t%s\t%s\t%s" % (
-        usrname, family_name, given_name, datatel, lang, affiliation
+    print "%s\t%s\t%s\t%s\t%s\t%s\t%s" % (
+        usrname, email, family_name, given_name, datatel, lang, affiliation
     )
 
 def dump_data(result_data):