def run(self, mapping):
        """
        generated_filename will return a filename similar to this:
            `20101107__wa__general__precinct.csv`

        election will return a filename similar to this:
            `20101102__wa__general__precinct`

        """

        generated_filename = mapping['generated_filename']
        election = mapping['election']

        """
        bad_filenames[] holds the list of files who have content that's
        hard to use (e.g. an .xls file with 10 sheets).

        The edge cases will be taken care of later. The cases where there is
        zero actual usable data will have to be rectified outside of the
        loader module.

        """

        bad_filenames = [
            # The below are Excel (.xls) files that have results spread across
            # multiple worksheets and in different structures from each other

            '20070821__wa__primary.xls',
            '20070821__wa__primary__county.xls',
            '20080219__wa__primary__adams__precinct.xls',
            '20080219__wa__primary__benton__precinct.xls',
            '20080219__wa__primary__congressional_district_state_legislative.xls',
            '20080219__wa__primary__douglas__precinct.xls',
            '20080219__wa__primary__kitsap__precinct.xls',
            '20080819__wa__primary__kitsap__precinct.xls',
            '20080819__wa__primary__pierce__precinct.xls',
            '20081104__wa__general__congressional_district.xls',
            '20081104__wa__general__adams__precinct.xls',
            '20091103__wa__general__clark__precinct.xls',
            '20081104__wa__general__franklin__precinct.xls',
            '20081104__wa__general__kittitas__precinct.xls',
            '20081104__wa__general__kitsap__precinct.xls',
            '20081104__wa__general__pierce__precinct.xls',
            '20081104__wa__general__precinct.xls',
            '20081104__wa__general__state_legislative.xls',
            '20091103__wa__general__kitsap__precinct.xls',
            '20091103__wa__general__pierce__precinct.xls',
            '20101102__wa__general__kittitas___precinct.xls',
            '20101102__wa__general__san_juan___precinct.xls',
            '20100817__wa__primary__state_legislative.xls',
            '20100817__wa__primary__congressional_district.xls',
            '20111108__wa__general__clark___precinct.xlsx',
            '20111108__wa__general__spokane___precinct.xlsx',
            '20120807__wa__primary__congressional_district.xls',
            '20120807__wa__primary__state_legislative.xls',
            '20121106__wa__general__congressional_district.xls',
            '20121106__wa__general__state_legislative.xls',
        ]

        """
        Could try using `generated_filename.split(.)[-1]` instead of
        os.path.splitext(election)[-1], since all filenames are
        standardized. This would, of course, break if the file path includes
        a full stop (period).

        """

        # If files are 'bad', skip them
        if any(x in generated_filename for x in bad_filenames):
            loader = SkipLoader()

        # If files are .xls(x), use the correct loader
        elif os.path.splitext(
                generated_filename)[-1].lower() in ('.xls', '.xlsx'):
            loader = WALoaderExcel()

        elif os.path.splitext(generated_filename)[-1].lower() == '.txt':

            """
            We run into issues where King County provides > 1 million line
            .txt files that break my machine's memory. We definitely need to
            refactor, but for the moment we'll pass over said files.

            """

            logger.info(
                'Cannot do anything with {0}'.format(generated_filename))
            loader = SkipLoader()

        elif 'precinct' in generated_filename:
            loader = WALoaderPrecincts()

        elif any(s in election for s in [
                '2000',
                '2001',
                '2002',
                '2003',
                '2004',
                '2005',
                '2006']):
            loader = WALoaderPre2007()

        elif os.path.splitext(
                generated_filename)[-1].lower() in ('.csv', '.txt'):
            loader = WALoaderPost2007()

        else:
            loader = SkipLoader()

        """
        * UnboundLocalError: File passes through the elif statements, but is
          not a file we have a loader class set up to handle at this point, so
          loader.run(mapping) is called before it's mentioned

        * IOError: File in quesiton does not exist. Seen when the mapping
          a file path that recieved a 404 error

        * unicodecsv.Error: Similar to UnboundLocalError, this error means
          that the loader tried running but the csv parser could not parse
          the file because of a null byte. See:
          https://github.com/jdunck/python-unicodecsv/blob/master/unicodecsv/test.py#L222

        * errors.InvalidOperation: When a file has no useful data, RawResult
          is empty and mongodb refuses to load it.

        Because of the if/else flow, sometimes we'll end up with multiple
        UnboundLocalErrors. This should be changed so we only get the error
        once.

        """

        try:
            loader.run(mapping)
        except UnboundLocalError:
            logger.error(
                '\tUnsupported file type ({0})'
                .format('UnboundLocalError'))
        except __HOLE__:
            logger.error(
                '\tFile "{0}" does not exist'
                .format(generated_filename))
        except unicodecsv.Error:
            logger.error(
                '\tUnsupported file type "({0})"'
                .format('unicodecsv.Error'))
        except errors.InvalidOperation:
            logger.error('\tNo raw results loaded')
dataset/ETHPy150Open openelections/openelections-core/openelex/us/wa/load.py/LoadResults.run