def parse_detailed_view(self, response):

        listing = response.meta['listing']
        stats = response.css('span.addr_bbs::text')
        for stat in stats:
            text = stat.extract()
            ans = re.search('bed', text)
            if ans is not None:
                listing['beds'] = float(re.search('(\d\S*)', text).group())
            ans = re.search('bath', text)
            if ans is not None:
                listing['baths'] = float(re.search('(\d\S*)', text).group())
            ans = re.search('sqft', text)
            if ans is not None:
                val = re.search('(\d\S*)', text).group()
                listing['sq_feet'] = parse_number(val, 'en_US')
        price = response.css('div.main-row > span::text').extract_first()
        if price is not None:
            listing['list_price'] = parse_number(
                re.search('(\d\S*)', price).group(), 'en_US')
        x = pd.DataFrame(listing,
                         columns=[
                             'z_id', 'street_address', 'city', 'state',
                             'zip_code', 'latitude', 'longitude', 'pgapt',
                             'sgapt', 'link', 'list_price', 'beds', 'baths',
                             'sq_feet'
                         ])
        yield x.to_csv("r", sep=",")
Example #2
0
def test_parse_number():
    assert numbers.parse_number('1,099', locale='en_US') == 1099
    assert numbers.parse_number('1.099', locale='de_DE') == 1099

    with pytest.raises(numbers.NumberFormatError) as excinfo:
        numbers.parse_number('1.099,98', locale='de')
    assert excinfo.value.args[0] == "'1.099,98' is not a valid number"
Example #3
0
def test_parse_number():
    assert numbers.parse_number('1,099', locale='en_US') == 1099
    assert numbers.parse_number('1.099', locale='de_DE') == 1099

    with pytest.raises(numbers.NumberFormatError) as excinfo:
        numbers.parse_number('1.099,98', locale='de')
    assert excinfo.value.args[0] == "'1.099,98' is not a valid number"
def parse_value(value):
    """
    Accepts a string value and attempts to parce it as a currency value.

    Returns the extracted numeric value converted to a string
    """
    l_currency_language_code, l_currency_code = _getCodes()

    curSym = get_currency_symbol(l_currency_code, l_currency_language_code)
    grpSym = get_group_symbol(locale=l_currency_language_code.lower())
    decSym = get_decimal_symbol(locale=l_currency_language_code.lower())

    # Convert the Official characters into what comes from the keyboard.
    #   This section may need to grow over time.
    #   - Character 160 is a non-breaking space, which is different from a typed space
    if ord(grpSym) == 160:
        value = value.replace(u' ', grpSym)

    allSym = _getSymbols(value)
    invalidSym = allSym.replace(curSym, '').replace(
        grpSym, '').replace(decSym, '').replace(u'-', '')

    value = value.replace(curSym, '')

    if allSym.count(decSym) > 1:
        raise NumberFormatError(default_error_messages['decimal_symbol'] % decSym)
    if (allSym.count(decSym) == 1 and allSym[-1] != decSym) or invalidSym:
        raise NumberFormatError(default_error_messages['invalid_format'] % (grpSym, decSym))
    if value.count(decSym) == 1:
        value = parse_decimal(value, locale=l_currency_language_code.lower())
    else:
        value = parse_number(value, locale=l_currency_language_code.lower())

    # The value is converted into a string because the parse functions return floats
    return str(value)
Example #5
0
def parse_number(string, locale=None):
    """Parses localized number string into a long integer.

    .. code-block:: python

       >>> parse_number('1,099', locale='en_US')
       1099L
       >>> parse_number('1.099', locale='de_DE')
       1099L

    When the given string cannot be parsed, an exception is raised:

    .. code-block:: python

       >>> parse_number('1.099,98', locale='de')
       Traceback (most recent call last):
           ...
       NumberFormatError: '1.099,98' is not a valid number

    :param string:
        The string to parse.
    :param locale:
        A locale code. If not set, uses the currently loaded locale.
    :returns:
        The parsed number.
    :raises:
        ``NumberFormatError`` if the string can not be converted to a number.
    """
    locale = locale or get_locale()
    return numbers.parse_number(string, locale=locale)
Example #6
0
 def parse(cls, original_value):
     try:
         python_value = parse_number(original_value) or parse_decimal(
             original_value)
         return cls(original_value, python_value)
     except NumberFormatError:
         pass
Example #7
0
def parselocal_number(txt, locale):
    """TODO

    :param txt: TODO
    :param locale: the current locale (e.g: en, en_us, it)
    """
    return numbers.parse_number(txt, locale)
Example #8
0
def simon_says_loop(driver: webdriver.Chrome,
                    queue,
                    target_score: int = 3000) -> int:
    try:
        WebDriverWait(driver, 2, 0.0001).until(
            EC.presence_of_element_located(
                (By.CSS_SELECTOR, "div.square-container")))
    except:
        queue.put(-1)
        return -1

    blinks = 2
    time.sleep(4)

    while True:
        is_playing = play_simon_says(driver, blinks)

        if not is_playing:
            return -1

        score_info = (WebDriverWait(driver, 5, 0.001).until(
            EC.visibility_of_element_located(
                (By.CSS_SELECTOR, "div.info-row span.right-info"))).text)
        score = score_info.split(" ")[0]
        score_int = parse_number(score, locale="de_DE")

        if score_int > target_score:
            time.sleep(40)
            break

        blinks += 1

    queue.put(0)
    return 0
def parse_number(string, locale=None):
    """Parses localized number string into a long integer.

    .. code-block:: python

       >>> parse_number('1,099', locale='en_US')
       1099L
       >>> parse_number('1.099', locale='de_DE')
       1099L

    When the given string cannot be parsed, an exception is raised:

    .. code-block:: python

       >>> parse_number('1.099,98', locale='de')
       Traceback (most recent call last):
           ...
       NumberFormatError: '1.099,98' is not a valid number

    :param string:
        The string to parse.
    :param locale:
        A locale code. If not set, uses the currently loaded locale.
    :returns:
        The parsed number.
    :raises:
        ``NumberFormatError`` if the string can not be converted to a number.
    """
    locale = locale or get_locale()
    return numbers.parse_number(string, locale=locale)
Example #10
0
def parse_value(value):
    """
    Accepts a string value and attempts to parce it as a currency value.

    Returns the extracted numeric value converted to a string
    """
    l_currency_language_code, l_currency_code = _getCodes()

    curSym = get_currency_symbol(l_currency_code, l_currency_language_code)
    grpSym = get_group_symbol(locale=l_currency_language_code.lower())
    decSym = get_decimal_symbol(locale=l_currency_language_code.lower())

    # Convert the Official characters into what comes from the keyboard.
    #   This section may need to grow over time.
    #   - Character 160 is a non-breaking space, which is different from a typed space
    if ord(grpSym) == 160:
        value = value.replace(u" ", grpSym)

    allSym = _getSymbols(value)
    invalidSym = allSym.replace(curSym, "").replace(grpSym, "").replace(decSym, "").replace(u"-", "")

    value = value.replace(curSym, "")

    if allSym.count(decSym) > 1:
        raise NumberFormatError(default_error_messages["decimal_symbol"] % decSym)
    elif (allSym.count(decSym) == 1 and allSym[-1] != decSym) or len(invalidSym) > 0:
        raise NumberFormatError(default_error_messages["invalid_format"] % (grpSym, decSym))
    elif value.count(decSym) == 1:
        value = parse_decimal(value, locale=l_currency_language_code.lower())
    else:
        value = parse_number(value, locale=l_currency_language_code.lower())

    # The value is converted into a string because the parse functions return
    # floats
    return str(value)
Example #11
0
 def clean(self, value):
     locale=get_current_language()
     if value != "":
         try:
             value = force_unicode(parse_number(value, locale=locale))
         except NumberFormatError:
             raise forms.ValidationError(self.error_messages['invalid'])
     return super(IntegerField, self).clean(value)
Example #12
0
def parselocal_number(txt, locale):
    """add???
    
    :param txt: add???
    :param locale: add???
    :returns: add???
    """
    return numbers.parse_number(txt, locale)
Example #13
0
def parselocal_number(txt, locale):
    """add???
    
    :param txt: add???
    :param locale: add???
    :returns: add???
    """
    return numbers.parse_number(txt, locale)
Example #14
0
 def parse_detailed_view(self, response):
     listing = response.meta['listing']
     stats = response.css('span.addr_bbs::text')
     for stat in stats:
         text = stat.extract()
         ans = re.search('bed', text)
         if ans is not None:
             listing['beds'] = float(re.search('(\d\S*)', text).group())
         ans = re.search('bath', text)
         if ans is not None:
             listing['baths'] = float(re.search('(\d\S*)', text).group())
         ans = re.search('sqft', text)
         if ans is not None:
             val = re.search('(\d+\S+)', text).group()
             listing['sq_feet'] = parse_number(val, 'en_US')
     price = response.css('div.main-row > span::text').extract_first()
     if price is not None:
         listing['list_price'] = parse_number(re.search('(\d+\S+)', price).group(), 'en_US')
     yield listing
Example #15
0
def parse_team_currency_value(string):
    try:
        value = parse_number(string)
        return value
    except:
        try:
            value = parse_decimal(string)
            return value
        except:
            return 0
Example #16
0
def parse_decimal(string, force_decimal=False):
    """Parse a localized decimal string into a float if `force_decimal` is
    False, else into a real :class:`decimal.Decimal` value.

    :param string: localized decimal string value
    :param force_decimal: whether to return Decimal instead of float
    """
    locale = get_locale()
    sep = numbers.get_decimal_symbol(locale)
    num, decimals = string.rsplit(sep, 1)
    num = numbers.parse_number(num, locale=locale)
    string = '%s.%s' % (num, decimals)
    return Decimal(string) if force_decimal else float(string)
Example #17
0
def parse_decimal(string, force_decimal=False):
    """Parse a localized decimal string into a float if `force_decimal` is
    False, else into a real :class:`decimal.Decimal` value.

    :param string: localized decimal string value
    :param force_decimal: whether to return Decimal instead of float
    """
    locale = get_locale()
    sep = numbers.get_decimal_symbol(locale)
    num, decimals = string.rsplit(sep, 1)
    num = numbers.parse_number(num, locale=locale)
    string = '%s.%s' % (num, decimals)
    return Decimal(string) if force_decimal else float(string)
Example #18
0
 def render(self, name, value, attrs=None):
     from babel.numbers import parse_number
     from babel.numbers import format_number
     from babel.numbers import NumberFormatError
     locale=get_current_language()
     if value is None: value = ""
     if value and isinstance(value, basestring):
         try:
             value = parse_number(value, locale=locale)
         except NumberFormatError:
             pass
     if value is not "" and not isinstance(value, basestring):
         value = format_number(value, locale=locale)
     return super(IntegerWidget, self).render(name, value, attrs)
Example #19
0
    def parse_number(self, string):
        """Parse localized number string into a long integer

        >>> Locale('en', 'US').parse_number('1,099')
        1099L
        >>> Locale('de', 'DE').parse_number('1.099')
        1099L

        When the given string cannot be parsed, an exception is raised:

        >>> Locale('de').parse_number('1.099,98')
        Traceback (most recent call last):
            ...
        NumberFormatError: '1.099,98' is not a valid number
        """
        return numbers.parse_number(string, self)
    def procesaDivFechas(self, divFecha):
        espTiempo = list(map(lambda x: x.strip(), divFecha.next.split("|")))

        reJornada = r"^JORNADA\s*(\d+)$"

        self.jornada = int(ExtractREGroups(cadena=espTiempo.pop(0), regex=reJornada)[0])
        cadTiempo = espTiempo[0] + " " + espTiempo[1]
        PATRONdmyhm = r'^\s*(\d{2}/\d{2}/\d{4})\s+(\d{2}:\d{2})?$'
        REhora = re.match(PATRONdmyhm, cadTiempo)
        patronH = PATRONFECHAHORA if REhora.group(2) else PATRONFECHA
        self.fechaPartido = pd.to_datetime(cadTiempo, format=patronH)

        spanPabellon = divFecha.find("span", {"class": "clase_mostrar1280"})
        self.Pabellon = spanPabellon.get_text().strip()

        textAsistencia = spanPabellon.next_sibling.strip()

        rePublico = r".*ico:\s*(\d+\.(\d{3})*)"
        grpsAsist = ExtractREGroups(cadena=textAsistencia, regex=rePublico)
        self.Asistencia = parse_number(grpsAsist[0], locale='de_DE') if grpsAsist else None
Example #21
0
def parse_number(string):
    """Parse localized number string into a long integer.

    >>> parse_number('1,099', locale='en_US')
    1099L
    >>> parse_number('1.099', locale='de_DE')
    1099L

    When the given string cannot be parsed, an exception is raised:

    >>> parse_number('1.099,98', locale='de')
    Traceback (most recent call last):
        ...
    NumberFormatError: '1.099,98' is not a valid number

    :param string:
        The string to parse.
    :return:
        The parsed number.
    :raise `NumberFormatError`:
        If the string can not be converted to a number
    """
    return numbers.parse_number(string, locale=local.locale)
Example #22
0
    def parse_number(self, string):
        """Parses localized number string into a long integer. Example::

            >>> parse_number('1,099', locale='en_US')
            1099L
            >>> parse_number('1.099', locale='de_DE')
            1099L

        When the given string cannot be parsed, an exception is raised::

            >>> parse_number('1.099,98', locale='de')
            Traceback (most recent call last):
               ...
            NumberFormatError: '1.099,98' is not a valid number

        :param string:
            The string to parse.
        :returns:
            The parsed number.
        :raises:
            ``NumberFormatError`` if the string can not be converted to a
            number.
        """
        return numbers.parse_number(string, locale=self.locale)
Example #23
0
 def parse_number(self, string):
     """Parse localized number string into a long integer
     """
     return numbers.parse_number(string, self)
Example #24
0
def parse_number(string):
    """Parse a localized number string into a long integer.
    """
    return numbers.parse_number(string, locale=get_locale())
Example #25
0
def parselocal_number(txt, locale):
    """TODO
    
    :param txt: TODO
    :param locale: the current locale (e.g: en, en_us, it)"""
    return numbers.parse_number(txt, locale)
Example #26
0
def parse_number(string):
    """Parse a localized number string into a long integer.
    """
    return numbers.parse_number(string, locale=get_locale())
Example #27
0
 def parse_number(self, strNum):
     return parse_number(strNum, locale=self.locale)