def get_daily_list(context, data_dict): # noinspection PyUnresolvedReferences """ Return a JSON dict representation of one or more instances of Daily. :param startDate: required, date of first Daily to return :type startDate: str :param endDate: optional, if omitted, only return Daily of startDate :type endDate: str :return: requested Daily or list of Daily :rtype: list of dict :raises: ValidationError """ output = [] start_date_str = _get_or_bust(data_dict, 'startDate') try: start_date = dt.strptime(start_date_str, '%Y-%m-%d') except ValueError: raise _ValidationError( 'startDate \'{0}\' not in YYYY-MM-DD format'.format(start_date_str) ) if 'endDate' in data_dict: end_date_str = data_dict['endDate'] try: end_date = dt.strptime(end_date_str, '%Y-%m-%d') except ValueError: raise _ValidationError( 'endDate \'{0}\' not in YYYY-MM-DD format'.format(end_date_str) ) days = (end_date - start_date).days + 1 if days < 1: raise _ValidationError(_( 'endDate \'{0}\' must be greater ' 'than startDate \'{1}\''.format( end_date_str, start_date_str ) )) else: days = 1 for day in range(days): single_date = (start_date + datetime.timedelta(days=day)).date() single_date_str = single_date.strftime('%Y-%m-%d') q = { 'q': ( 'product_type_code:24 AND ' 'release_date:"{0}T08:30:00Z"'.format( single_date_str ) ) } results = _get_action('package_search')(context, q) count = results['count'] if count > 1: raise _ValidationError( 'More than one Daily for date \'{0}\''.format(single_date_str) ) for result in results['results']: children = [] for child in result.get('child_list', []): children.append( get_product(context, { 'productId': child }) ) result['children'] = children output.append(result) return output
def get_daily_list(context, data_dict): # noinspection PyUnresolvedReferences """ Return a JSON dict representation of one or more instances of Daily. :param startDate: required, date of first Daily to return :type startDate: str :param endDate: optional, if omitted, only return Daily of startDate :type endDate: str :return: requested Daily or list of Daily :rtype: list of dict :raises: ValidationError """ output = [] start_date_str = _get_or_bust(data_dict, 'startDate') try: start_date = dt.strptime(start_date_str, '%Y-%m-%d') except ValueError: raise _ValidationError('startDate \'{0}\' not in YYYY-MM-DD format'.format(start_date_str)) if 'endDate' in data_dict: end_date_str = data_dict['endDate'] try: end_date = dt.strptime(end_date_str, '%Y-%m-%d') except ValueError: raise _ValidationError('endDate \'{0}\' not in YYYY-MM-DD format'.format(end_date_str)) days = (end_date - start_date).days + 1 if days < 1: raise _ValidationError( _('endDate \'{0}\' must be greater than startDate \'{1}\''.format(end_date_str, start_date_str))) else: days = 1 for day in range(days): single_date = (start_date + datetime.timedelta(days=day)).date() single_date_str = single_date.strftime('%Y-%m-%d') q = {'q': 'product_type_code:24 AND release_date:{0}T08\:30'.format(single_date_str)} result = _get_action('package_search')(context, q) count = result['count'] if count == 0: raise _NotFound('Daily not found for date \'{0}\''.format(single_date_str)) elif count > 1: raise _ValidationError('More than one Daily for date \'{0}\''.format(single_date_str)) else: daily_output = {} extras = result['results'][0]['extras'] for extra in extras: daily_output[extra['key']] = extra['value'] if extra['key'] == 'child_list': children = [] child_ids = extra['value'].split('; ') for child_id in child_ids: child_result = get_product(context, {'productId': child_id}) for a_child_result in child_result: children.append(a_child_result) daily_output['children'] = children output.append(daily_output) return output
def get_daily_list(context, data_dict): # noinspection PyUnresolvedReferences """ Return a JSON dict representation of one or more instances of Daily. :param startDate: required, date of first Daily to return :type startDate: str :param endDate: optional, if omitted, only return Daily of startDate :type endDate: str :return: requested Daily or list of Daily :rtype: list of dict :raises: ValidationError """ output = [] start_date_str = _get_or_bust(data_dict, 'startDate') try: dt.strptime(start_date_str, '%Y-%m-%d') except ValueError: raise _ValidationError( 'startDate \'{0}\' not in YYYY-MM-DD format'.format( start_date_str)) start_date = parse(start_date_str, default=default_release_date).astimezone(gettz('UTC')) if 'endDate' in data_dict: end_date_str = data_dict['endDate'] try: dt.strptime(end_date_str, '%Y-%m-%d') except ValueError: raise _ValidationError( 'endDate \'{0}\' not in YYYY-MM-DD format'.format( end_date_str)) end_date = parse(end_date_str, default=default_release_date).astimezone(gettz('UTC')) days = (end_date - start_date).days + 1 if days < 1: raise _ValidationError( _('endDate \'{0}\' must be greater ' 'than startDate \'{1}\''.format(end_date_str, start_date_str))) else: days = 1 for day in range(days): single_date = (start_date + datetime.timedelta(days=day)) single_date_str = single_date.replace(tzinfo=None).isoformat() q = { 'q': ('product_type_code:24 AND ' 'last_release_date:"{release_date}Z"'.format( release_date=single_date_str)) } results = _get_action('package_search')(context, q) count = results['count'] if count > 1: raise _ValidationError( 'More than one Daily for date \'{0}\''.format(single_date_str)) for result in results['results']: children = [] for child in result.get('child_list', []): children.append(get_product(context, {'productId': child})) result['children'] = children output.append(result) return output