Exemple #1
0
def check_valid_dates(from_date, to_date):
    """
    Check if it's a valid date range
    
    :param from_date: date should scrape from
    :param to_date: date should scrape to
    
    :return: None
    """
    try:
        if time.strptime(to_date, "%Y-%m-%d") < time.strptime(from_date, "%Y-%m-%d"):
            raise shared.HaltException("Error: The second date input is earlier than the first one")
    except ValueError:
        raise shared.HaltException("Error: Incorrect format given for dates. They must be given like 'yyyy-mm-dd' "
                                   "(ex: '2016-10-01').")
Exemple #2
0
def check_data_format(data_format):
    """
    Checks if data_format specified (if it is at all) is either None, 'Csv', or 'pandas'.
    It exits program with error message if input isn't good.
    
    :param data_format: data_format provided 
    
    :return: Boolean - True if good
    """
    if not data_format or data_format.lower() not in ['csv', 'pandas']:
        raise shared.HaltException('{} is an unspecified data format. The two options are Csv and Pandas '
                                   '(Csv is default)\n'.format(data_format))
def check_date_format(date):
    """
    Verify the date format. If wrong raises a HaltException

    :param date: User supplied date

    :return: None
    """
    try:
        time.strptime(date, "%Y-%m-%d")
    except ValueError:
        raise shared.HaltException(
            "Error: Incorrect format given for dates. They must be given like 'yyyy-mm-dd' "
            "(ex: '2016-10-01').")