Source code for uw.local.watiam.bin.download_check

"""WatIAM download check process.

This is run after every download of the WatIAM Extract.  It looks for
duplicate IDs in the WatIAM information and reports them to WatIAM staff.
"""

from sys import argv

from uw.emailutils import emailaddr

from uw.sql.wrap import ConnectionPool, open_psycopg2_db_service_connection
from uw.local.dbtools import Cursor

from ...util.mail import odyssey_email
from ...outgoing.make_mail import mailout

check_views = (
    ('check_duplicate_uw_id', 'Duplicate UW IDs'),
    ('check_duplicate_hr_id', 'Duplicate HR IDs'),
    ('check_invalid_pdbid', 'Invalid PDBIDs'),
    ('check_invalid_uw_id', 'Invalid UW IDs'),
    ('check_invalid_hr_id', 'Invalid HR IDs'),
)

target_email = emailaddr ('WatIAM Problem Reports', 'watiam-problems@odyssey.uwaterloo.ca')

[docs]def main (): if len (argv) != 1: raise ValueError ('No parameters expected') connection_pool = ConnectionPool (open_psycopg2_db_service_connection (), Cursor) connection = connection_pool.connect () cursor = connection.cursor () error_text = '' for check_view, message in check_views: errors = cursor.execute_tuples ("select * from %s" % check_view) if errors: error_text += '\n%s:\n' % message for error in errors: error_text += '\t'.join (map (str, error)) + '\n' if error_text: content = 'There were problems with the most recent WatIAM Extract load.\n' + error_text message = mailout (cursor, odyssey_email, 'CSCF: WatIAM Extract Problems', content) message.add_recipient ('To', target_email) message.done () cursor.connection.commit ()