Ejemplo n.º 1
0
def regular_time(time):
    """
    # 规范化中标时间格式
    :param time:
    :return:
    """
    if len(time) > 0:
        y, m, d = re.split(u"年|月|日|\.|-", time)[:3]
        dict_cn_number_year = dict([(x, 0) for x in u"○〇OО0oO"])
        dict_cn_number_year.update(util.DICT_CN_SIMPLE_NUMBER)
        if y[0] in dict_cn_number_year:
            t = ""
            for w in y:
                t += str(int(dict_cn_number_year.get(w)))
            y = t
        if m[0] in util.DICT_CN_SIMPLE_NUMBER:
            m = str(int(util.convert_cn_number(m)))
        if d[0] in util.DICT_CN_SIMPLE_NUMBER:
            d = str(int(util.convert_cn_number(d)))

        try:
            time = datetime.date(year=int(y), month=int(m), day=int(d))
            time = time.strftime("%Y-%m-%d")
        except ValueError, e:
            # print "ValueError:", time
            return None
Ejemplo n.º 2
0
def regulate_money(money_info):
    """
    规范化中标金额格式,
       将amount转换成float、unit转换成以元为单位
       将currency调整为 人民币,美元 等
    :param money_info:
    :return:
    """
    amount, unit, currency = money_info[MONEY_AMOUNT], money_info[MONEY_UNIT], money_info[MONEY_CURRENCY]

    if isinstance(amount, (str, unicode)) and len(amount) == 0:
        amount = None
    if isinstance(unit, (str, unicode)) and len(unit) == 0:
        unit = None
    if isinstance(currency, (str, unicode)) and len(currency) == 0:
        currency = None
    if amount is not None:
        if amount[0] in u"壹贰叁肆伍陆柒捌玖拾":
            amount = util.convert_cn_number(amount)
            unit = u"元"
            currency = u"人民币"
        else:
            amount = re.sub(u",|,", u"", amount)
            amount = float(amount)
            if unit is not None and unit[0] in util.DICT_CN_COMPLEX_NUMBER:
                amount *= util.DICT_CN_COMPLEX_NUMBER.get(unit[0])
                unit = unit[1:]
    if currency is not None:
        if currency in (u"人民币", u"¥", u'¥', u"RMB", u"CNY"):
            currency = u"人民币"
        elif currency in (u"美元", u"$", u"USD"):
            currency = u"美元"
        elif currency in (u"欧元", u"€", u"EUR"):
            currency = u"欧元"
    else:
        if amount and unit:
            currency = u"人民币"

    if unit is None and amount and currency:
        if currency == u"人民币":
            unit = u"元"
        elif currency == u"美元":
            unit = u"美元"
        elif currency == u"欧元":
            unit = u"欧元"

    res = {
        MONEY_AMOUNT: amount,
        MONEY_UNIT: unit,
        MONEY_CURRENCY: currency
    }

    return res
Ejemplo n.º 3
0
def regulate_number_string(number_string):
    number = None

    if len(number_string) > 0:
        try:
            if number_string[0] in util.DICT_CN_SIMPLE_NUMBER:
                number = int(util.convert_cn_number(number_string))
            else:
                number = int(number_string)
        except ValueError:
            pass

    return number
Ejemplo n.º 4
0
def regular_money(money_info):
    """
    # 规范化中标金额格式
    :param money_info:
    :return:
    """
    money, unit = money_info["money"], money_info["unit"]
    if isinstance(unit, (str, unicode)) and len(unit) == 0:
        unit = None
    if isinstance(money, (str, unicode)) and len(money) == 0:
        money = None
    if money is not None:
        if money[0] in u"壹贰叁肆伍陆柒捌玖拾":
            money = util.convert_cn_number(money)
        else:
            money = re.sub(u",|,", u"", money)
            money = float(money)
            if unit is not None and unit[0] in util.DICT_CN_COMPLEX_NUMBER:
                money *= util.DICT_CN_COMPLEX_NUMBER.get(unit[0])
                unit = unit[1:]
    money_info["money"] = money
    money_info["unit"] = unit
    return money_info