# Path: cli.py
# def setup_logger(loglevel):
#     loglevel = LOGLEVELS.get(loglevel.upper())
#     if loglevel is None:
#         loglevel = LOGLEVELS['INFO']
#     logger = logging.getLogger()
#     logger.setLevel(loglevel)
#     formatter = logging.Formatter(DEFAULT_LOG_FORMAT)
#     console_handler = logging.StreamHandler(stream=sys.stdout)
#     console_handler.setLevel(loglevel)
#     console_handler.setFormatter(formatter)
#     logger.addHandler(console_handler)
# 
# Path: cli.py
# def add_logging_options(parser):
#     parser.add_argument(
#         '--loglevel',
#         help='Log level, one of INFO, ERROR, WARN, DEBUG or CRITICAL.',
#         default='INFO',
#     )
# 
# Path: cli.py
# CMD_LINE_DATE_FORMAT = '%Y-%m-%d'


import os
import sys
import json
import logging
import argparse
import urllib.parse as urlparse
import elasticsearch
import botocore
import boto3
from datetime import datetime
from datetime import timedelta
from cli import setup_logger
from cli import add_logging_options
from cli import CMD_LINE_DATE_FORMAT
from capitolweb.workers.crec_parser import CRECParser




MODS_KEY_TEMPLATE = 'crec/%Y/%m/%d/mods/mods.xml'


if __name__ == '__main__':
    logging.basicConfig(level=20,)
    parser = argparse.ArgumentParser()
    add_logging_options(parser)
    output_option_group = parser.add_mutually_exclusive_group(required=True)
    output_option_group.add_argument(
        '--to_stdout',
        action='store_true',
        help='If true, will not upload to es and instead print to stdout.',
    )
    output_option_group.add_argument(
        '--es_url',
        help='Elastic search URL to upload records to.',
    )
    parser.add_argument(
        '--start_dt',
        help='Start of date range to pull data for, inclusive.',
        type=lambda d: datetime.strptime(d, CMD_LINE_DATE_FORMAT),
        default=None,
    )
    parser.add_argument(
        '--end_dt',
        help='End of date range to pull data for, exclusive.',

# Path: cli.py
# def setup_logger(loglevel):
#     loglevel = LOGLEVELS.get(loglevel.upper())
#     if loglevel is None:
#         loglevel = LOGLEVELS['INFO']
#     logger = logging.getLogger()
#     logger.setLevel(loglevel)
#     formatter = logging.Formatter(DEFAULT_LOG_FORMAT)
#     console_handler = logging.StreamHandler(stream=sys.stdout)
#     console_handler.setLevel(loglevel)
#     console_handler.setFormatter(formatter)
#     logger.addHandler(console_handler)
# 
# Path: cli.py
# def add_logging_options(parser):
#     parser.add_argument(
#         '--loglevel',
#         help='Log level, one of INFO, ERROR, WARN, DEBUG or CRITICAL.',
#         default='INFO',
#     )
# 
# Path: cli.py
# CMD_LINE_DATE_FORMAT = '%Y-%m-%d'


# Path: run_crec_es_uploader.py
import os
import sys
import json
import logging
import argparse
import urllib.parse as urlparse
import elasticsearch
import botocore
import boto3
from datetime import datetime
from datetime import timedelta
from cli import setup_logger
from cli import add_logging_options
from cli import CMD_LINE_DATE_FORMAT
from capitolweb.workers.crec_parser import CRECParser





MODS_KEY_TEMPLATE = 'crec/%Y/%m/%d/mods/mods.xml'


if __name__ == '__main__':
    logging.basicConfig(level=20,)
    parser = argparse.ArgumentParser()
    add_logging_options(parser)
    output_option_group = parser.add_mutually_exclusive_group(required=True)
    output_option_group.add_argument(
        '--to_stdout',
        action='store_true',
        help='If true, will not upload to es and instead print to stdout.',
    )
    output_option_group.add_argument(
        '--es_url',
        help='Elastic search URL to upload records to.',
    )
    parser.add_argument(
        '--start_dt',
        help='Start of date range to pull data for, inclusive.',
        type=lambda d: datetime.strptime(d, CMD_LINE_DATE_FORMAT),
        default=None,
    )
    parser.add_argument(
        '--end_dt',
        help='End of date range to pull data for, exclusive.',

        type=lambda d: datetime.strptime(d, CMD_LINE_DATE_FORMAT),