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():
"""
else:
# dump_data(result_data)
insert_into_staging(result_data)
- print(r'\.')
+ print(r'\.')
except ldap.LDAPError, e:
print e
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):