# Path: importer/importer/utils/parsing.py

# 
# Path: importer/importer/utils/collections.py
# def find_first(needles, haystack):
#     for needle in needles:
#         if needle in haystack:
#             return needle
# 
# Path: importer/importer/utils/strings.py
# def strip_links(text):
#     return link_expression.sub('\\1', text)
# 
# def find_numbers(text):
#     return [
#         int(''.join(filter(str.isdigit, s)))
#         for s in number_expression.findall(text)
#         if s.strip()
#     ]
# 
# def is_from_string(text):
#     return bool(from_expression.match(text))
# 
# def is_up_to_string(text):
#     return bool(up_to_expression.match(text))


from operator import itemgetter
from funcy import flatten, project, first
from datetime import datetime, time, timedelta
from isodate import parse_date
from .utils.parsing import maybe_parse_date, maybe_parse_time
from .utils.collections import find_first
from .utils.strings import (
    strip_links,
    find_numbers,
    is_from_string,
    is_up_to_string,
)

    return {
        'text': price_text,
        'lower': lower,
        'upper': upper,
    }


def transform_phone(phone_text):
    return list(filter(bool, map(str.strip, phone_text.split(','))))


def transform_coords(coords):
    if coords is None:
        return None

    lat, lon = coords.get('lat'), coords.get('lon')
    if not lat or not lon:
        return None

    return {
        'lat': float(lat),
        'lon': float(lon),
    }


def transform_date(spec):
    start_date = parse_date(spec['start_date'])
    start_time = maybe_parse_time(spec['start_time']) or time(0, 0)
    end_date = maybe_parse_date(spec['end_date']) or start_date

# Path: importer/importer/utils/parsing.py

# 
# Path: importer/importer/utils/collections.py
# def find_first(needles, haystack):
#     for needle in needles:
#         if needle in haystack:
#             return needle
# 
# Path: importer/importer/utils/strings.py
# def strip_links(text):
#     return link_expression.sub('\\1', text)
# 
# def find_numbers(text):
#     return [
#         int(''.join(filter(str.isdigit, s)))
#         for s in number_expression.findall(text)
#         if s.strip()
#     ]
# 
# def is_from_string(text):
#     return bool(from_expression.match(text))
# 
# def is_up_to_string(text):
#     return bool(up_to_expression.match(text))


# Path: importer/importer/transform.py
from operator import itemgetter
from funcy import flatten, project, first
from datetime import datetime, time, timedelta
from isodate import parse_date
from .utils.parsing import maybe_parse_date, maybe_parse_time
from .utils.collections import find_first
from .utils.strings import (
    strip_links,
    find_numbers,
    is_from_string,
    is_up_to_string,
)


    return {
        'text': price_text,
        'lower': lower,
        'upper': upper,
    }


def transform_phone(phone_text):
    return list(filter(bool, map(str.strip, phone_text.split(','))))


def transform_coords(coords):
    if coords is None:
        return None

    lat, lon = coords.get('lat'), coords.get('lon')
    if not lat or not lon:
        return None

    return {
        'lat': float(lat),
        'lon': float(lon),
    }


def transform_date(spec):
    start_date = parse_date(spec['start_date'])
    start_time = maybe_parse_time(spec['start_time']) or time(0, 0)
    end_date = maybe_parse_date(spec['end_date']) or start_date

    end_time = maybe_parse_time(spec['end_time']) or start_time