def _cleaner(k, v): ''' A helper function that is used for renaming dictionary keys and formatting dates. ''' def is_other(data): if not common.get_p_number(data) and \ not common.get_k_number(data) and \ not data.startswith('G'): return True return False k = k.lower() if k in RENAME_MAP: k = RENAME_MAP[k] if k == 'product_submission_numbers': # We take this single key, split it on space and then return three new # keys and not the original. submissions = [s for s in v.split(' ') if s] k_numbers = [d for d in submissions if common.get_k_number(d)] pma_numbers = [d for d in submissions if common.get_p_number(d)] other = ' '.join([d.strip() for d in submissions if is_other(d)]) return [('k_numbers', k_numbers), ('pma_numbers', pma_numbers), ('other_submission_description', other)] if v != None: if k in DATE_KEYS: # Elasticsearch cannot handle null dates, emit None so the wrapper # function `transform_dict` will omit it from its transformation if not v: return None v = arrow.get(v, 'YYYY/MM/DD HH:mm:ss').format('YYYY-MM-DD') else: return (k, v.strip()) return (k, v)
def _cleaner(k, v): ''' A helper function that is used for renaming dictionary keys and formatting dates. ''' def is_other(data): if not common.get_p_number(data) and \ not common.get_k_number(data) and \ not data.startswith('G'): return True return False k = k.lower() if k in RENAME_MAP: k = RENAME_MAP[k] else: return None if k == 'product_submission_numbers': # We take this single key, split it on space and then return three new # keys and not the original. submissions = [s for s in v.split(' ') if s] k_numbers = [d for d in submissions if common.get_k_number(d)] pma_numbers = [ d for d in submissions if common.get_p_number(d) ] other = ' '.join( [d.strip() for d in submissions if is_other(d)]) return [('k_numbers', k_numbers), ('pma_numbers', pma_numbers), ('other_submission_description', other)] if v != None: return (k, v.strip()) return (k, v)
def _cleaner(k, v): ''' A helper function that is used for renaming dictionary keys and formatting dates. ''' def is_other(data): if not common.get_p_number(data) and \ not common.get_k_number(data) and \ not data.startswith('G'): return True return False k = k.lower() if k in RENAME_MAP: k = RENAME_MAP[k] if k == 'product_submission_numbers': # We take this single key, split it on space and then return three new # keys and not the original. submissions = [s for s in v.split(' ') if s] k_numbers = [d for d in submissions if common.get_k_number(d)] pma_numbers = [ d for d in submissions if common.get_p_number(d) ] other = ' '.join( [d.strip() for d in submissions if is_other(d)]) return [('k_numbers', k_numbers), ('pma_numbers', pma_numbers), ('other_submission_description', other)] if v != None: if k in DATE_KEYS: # Elasticsearch cannot handle null dates, emit None so the wrapper # function `transform_dict` will omit it from its transformation if not v: return None v = arrow.get(v, 'YYYY/MM/DD HH:mm:ss').format('YYYY-MM-DD') else: return (k, v.strip()) return (k, v)
def is_other(data): if not common.get_p_number(data) and \ not common.get_k_number(data) and \ not data.startswith('G'): return True return False