Ejemplo n.º 1
0
def promo_parser(task, rule): 
    promos = [] 
    try:
        item = json.loads(task["text"])
    except ValueError as e:
        log_with_time(e)
        return format_promo([(task["crc"], promos)])
    if int(item.get("errno", "1")) != 0: 
        log_with_time("errno not zero")
        return format_promo([(task["crc"], promos)])

    for i in item["data"]:
        for j in i["info_list"]:
            tp = int(j["discount_type"])
            if tp == 5:
                #满减
                promos.append({
                    "keywords": "满减",
                    "type": 1,
                    "desc": j["name"]
                    }) 
            #7, 8, 加价换购, 10推荐活动忽略 
            elif tp == 9:
                promo_id = j["promotion_ruleid"] 
                more = []
                for m in item["data"]:
                    if m["item_ruleid"] == promo_id:
                        more.append(m["title"])
                promos.append({
                    "keywords": "满赠",
                    "type": 3,
                    "desc": u"%s: %s" %  (j["name"], ", ".join(more))
                    })
            elif tp == 11:
                #可领券 
                promos.append({
                    "keywords": "赠券",
                    "type": 3,
                    "desc": j["desc"].encode("utf8").replace("点击领券!", "")
                    }) 

    ret = [(task["crc"], promos)]
    return format_promo(ret)
Ejemplo n.º 2
0
def promo_parser(task, rule):
    promos = []
    try:
        item = json.loads(task["text"])
    except ValueError as e:
        log_with_time(e)
        return format_promo([(task["crc"], promos)])
    if int(item.get("errno", "1")) != 0:
        log_with_time("errno not zero")
        return format_promo([(task["crc"], promos)])

    for i in item["data"]:
        for j in i["info_list"]:
            tp = int(j["discount_type"])
            if tp == 5:
                #满减
                promos.append({"keywords": "满减", "type": 1, "desc": j["name"]})
            #7, 8, 加价换购, 10推荐活动忽略
            elif tp == 9:
                promo_id = j["promotion_ruleid"]
                more = []
                for m in item["data"]:
                    if m["item_ruleid"] == promo_id:
                        more.append(m["title"])
                promos.append({
                    "keywords": "满赠",
                    "type": 3,
                    "desc": u"%s: %s" % (j["name"], ", ".join(more))
                })
            elif tp == 11:
                #可领券
                promos.append({
                    "keywords":
                    "赠券",
                    "type":
                    3,
                    "desc":
                    j["desc"].encode("utf8").replace("点击领券!", "")
                })

    ret = [(task["crc"], promos)]
    return format_promo(ret)
Ejemplo n.º 3
0
def promo_parser(task, rule):
    promos = []
    if len(task["text"]) < 200:
        log_with_time("no promo info")
        ret = [(task["crc"], promos)]
        return format_promo(ret)
    try:
        j = jsonp_json(task["text"])
    except ValueError:
        log_with_time("json error: %s" % task["text"])
        ret = [(task["crc"], promos)]
        return format_promo(ret)
    if not j:
        log_with_time("json null: %s" % task["text"])
        ret = [(task["crc"], promos)]
        return format_promo(ret)
    if j.get("mpt"):
        price = Decimal(j.get("mpt").split(",")[0])
        promos.append({
            "keywords": "手机专享价",
            "type": 9,
            "desc": "手机专享价: %s" % price,
        })
    for i in j["promotionInfoList"]:
        ptype = i["promoType"]
        if i.get("addMoney") and float(i.get("addMoney")):
            continue
        if i.get("userLevel", 0) > 50:
            continue
        if ptype == 1:
            if not i.get("needJBeanNum"):
                i["needJBeanNum"] = 0
            if i["needJBeanNum"] > 0 and i.get("price", 0) > 0:
                #京豆优惠购
                promos.append({
                    "desc":
                    "京豆优惠购",
                    "type":
                    11,
                    "desc":
                    "使用%s京豆可享受优惠价%s" %
                    (Decimal(i["needJBeanNum"]), Decimal(i["price"]))
                })
            if i.get("adwordCouponList"):
                s = coupon(i["adwordCouponList"])
                if s:
                    promos.append({
                        "desc": "赠%s京券" % s,
                        "keywords": "赠券",
                        "type": 3,
                    })
            if i.get("score"):
                #送京豆
                promos.append({
                    "keywords": "送京豆",
                    "type": 3,
                    "desc": "送京豆%s个" % i["score"]
                })
            if i.get("extType") == 8:
                #团购
                promos.append({"keywords": "闪团", "type": 8, "desc": "闪团"})
        elif ptype == 15:
            if i["rebate"] > 0:
                promos.append({
                    "desc": "封顶",
                    "type": 11,
                    "desc": "封顶%s折" % float(10 * i["rebate"])
                })
        elif ptype == 4:
            if i.get("adwordGiftSkuList"):
                s = []
                for m in i["adwordGiftSkuList"]:
                    #1是附件
                    if m["giftType"] == 2:
                        s.append("%s x %s" %
                                 (m["name"].replace(" ", ""), m["number"]))
                if s:
                    promos.append({
                        "keywords": "赠品",
                        "type": 3,
                        "desc": u"赠 " + ", ".join(s)
                    })
            #赠券
            if i.get("adwordCouponList"):
                s = coupon(i["adwordCouponList"])
                if s:
                    promos.append({
                        "desc": "赠%s京券" % s,
                        "keywords": "赠券",
                        "type": 3,
                    })
            #赠京豆
            if i.get("score") and float(i["score"]):
                promos.append({
                    "keywords": "送京豆",
                    "type": 3,
                    "desc": "送京豆%s个" % i["score"]
                })
        elif ptype == 10:
            ftype = i["fullRefundType"]
            if ftype == 1:
                for m in i["fullLadderDiscountList"]:
                    #加价购忽略
                    if m.get("addMoney") and Decimal(m["addMoney"]):
                        continue
                    #非满减
                    if not m["needMoney"]:
                        continue
                    m["needMoney"] = Decimal(m["needMoney"])
                    m["rewardMoney"] = Decimal(m["rewardMoney"])
                    m["percent"] = Decimal(m.get("percent", 0))
                    if m["needMoney"] and m["rewardMoney"]:
                        promos.append({
                            "keywords":
                            "满减",
                            "type":
                            1,
                            "desc":
                            "满%s减%s" % (m["needMoney"], m["rewardMoney"]),
                        })
                    if m["needMoney"] and not m["rewardMoney"] and not m[
                            "percent"]:
                        promos.append({
                            "keywords": "满赠",
                            "type": 3,
                            "desc": "满%s赠热销商品" % (m["needMoney"])
                        })
                    #满赠
                    if m.get("haveFullRefundGifts"):
                        if m["needMoney"] and ["rewardMoney"]:
                            promos.append({
                                "keywords":
                                "满送",
                                "type":
                                3,
                                "desc":
                                "满%s减%s,得赠品" %
                                (m["needMoney"], m["rewardMoney"]),
                            })
                        elif m["needMoney"]:
                            promos.append({
                                "keywords": "满送",
                                "type": 3,
                                "desc": "满%s即赠热销商品" % m["needMoney"]
                            })
                    #满赠券
                    if m.get("adwordCouponList") and i["needMoney"]:
                        s = coupon(m["adwordCouponList"])
                        if s:
                            promos.append({
                                "keywords":
                                "满送券",
                                "type":
                                3,
                                "desc":
                                "满%s送%s京券" % (m["needMoney"], s)
                            })
                    if m["needMoney"] and m["percent"]:
                        promos.append({
                            "keywords":
                            "满%s可享折扣" % m["needMoney"],
                            "type":
                            1,
                            "desc":
                            "满%s减%s%%" % (m["needMoney"], m["percent"])
                        })
            elif ftype == 2:
                if not i.get("needMondey"):
                    continue
                if float(i["needMondey"]) and i["reward"]:
                    if i.get("topMoney") and float(i["topMoney"]):
                        promos.append({
                            "desc":
                            "多次满减",
                            "type":
                            1,
                            "desc":
                            "每满%s可减%s现金, 最多可减 %s" %
                            (Decimal(i["needMondey"]), Decimal(
                                i["reward"]), Decimal(i["topMoney"]))
                        })
                    else:
                        promos.append({
                            "keywords":
                            "多次满减",
                            "type":
                            1,
                            "desc":
                            "每满%s可减%s现金" %
                            (Decimal(i["needMondey"]), Decimal(i["reward"]))
                        })
                    if i["needMondey"] and i["adwordCouponList"]:
                        s = coupon(i["adwordCouponList"])
                        if s:
                            promos.append({
                                "keywords":
                                "满送券",
                                "type":
                                3,
                                "desc":
                                "每满%s即赠%s元京券" %
                                (Decimal(i["needMondey"]), Decimal(s))
                            })
            elif ftype == 6:
                s = []
                for m in i["fullLadderDiscountList"]:
                    if Decimal(m["needMoney"]) and Decimal(m["rewardMoney"]):
                        s.append("满%s减%s" % (Decimal(
                            m["needMoney"]), Decimal(m["rewardMoney"])))
                if s:
                    promos.append({
                        "keywords": "满减",
                        "type": 1,
                        "desc": ", ".join(s)
                    })
            elif ftype == 20:
                log_with_time("ftype 20: %s" % task["url"])
            elif ftype == 11:
                if i["needNum"] and i["deliverNum"]:
                    promos.append({
                        "keywords":
                        "多买多惠",
                        "type":
                        11,
                        "desc":
                        "买%s立减%s件商品价格" % (i["needNum"], i["deliverNum"])
                    })
            elif ftype == 13:
                if i.get("needMondey") and i.get("deliverNum"):
                    promos.append({
                        "keywords":
                        "多件优惠",
                        "type":
                        11,
                        "desc":
                        "%s元可买%s件" %
                        (Decimal(i["needMondey"]), i["deliverNum"]),
                    })
            elif ftype == 14:
                #满needNum赠热销商品
                if i.get("needNum") and i.get("rebate"):
                    promos.append({
                        "keywords":
                        "多件优惠",
                        "type":
                        11,
                        "desc":
                        "满%s件总价打%s折" %
                        (Decimal(i["needNum"]), float(10 * i["rebate"]))
                    })
                elif i.get("needNum"):
                    promos.append({
                        "keywords": "满赠",
                        "type": 3,
                        "desc": "满%s件即赠热销商品" % i["needNum"]
                    })
            elif ftype == 15:
                s = []
                for m in i["fullLadderDiscountList"]:
                    if m.get("addMoney") and float(m["addMoney"]):
                        continue
                    if m["needNum"] and m["rebate"]:
                        s.append("满%s件总价打%s折" %
                                 (m["needNum"], float(10 * m["rebate"])))
                if s:
                    promos.append({
                        "keywords": "多买优惠",
                        "type": 11,
                        "desc": ", ".join(s)
                    })
            elif ftype == 16:
                mtype = i["mfmzExtType"]
                if mtype == 0:
                    s = []
                    for m in i["fullLadderDiscountList"]:
                        if m.get("addMoney") and float(m["addMoney"]):
                            continue
                        if m.get("needNum") and m.get("rebate"):
                            s.append("满%s件总价打%s折" %
                                     (m["needNum"], float(10 * m["rebate"])))
                    if s:
                        promos.append({
                            "keywords": "满减",
                            "type": 3,
                            "desc": ", ".join(s)
                        })
                elif mtype == 1 or mtype == 3:
                    #fullLadderDiscountList, 阶梯满减
                    s = []
                    for m in i["fullLadderDiscountList"]:
                        if m["needMoney"] and m["rewardMoney"]:
                            s.append("满%s减%s" % (Decimal(
                                m["needMoney"]), Decimal(m["rewardMoney"])))
                    if s:
                        promos.append({
                            "keywords": "满减",
                            "type": 1,
                            "desc": ", ".join(s)
                        })
                if mtype == 2:
                    for m in i["fullLadderDiscountList"]:
                        if m["needMoney"]:
                            promos.append({
                                "keywords":
                                "满赠",
                                "type":
                                3,
                                "desc":
                                "满%s即赠热销商品" % Decimal(m["needMoney"])
                            })
                elif mtype == 4:
                    s = []
                    for m in i["fullLadderDiscountList"]:
                        if m["needMoney"]:
                            s.append("满%s得赠品" % Decimal(m["needMoney"]))
                    if s:
                        promos.append({
                            "keywords": "满赠",
                            "type": 3,
                            "desc": ",".join(s)
                        })
                elif mtype == 5:
                    s = []
                    for m in i["fullLadderDiscountList"]:
                        if m["needMoney"] and m["rewardMoney"] and m[
                                "mfmzTag"] == 1:
                            s.append("满%s立减%s" % (Decimal(
                                m["needMoney"]), Decimal(m["rewardMoney"])))
                    if s:
                        promos.append({
                            "keywords": "满减",
                            "type": 1,
                            "desc": ", ".join(s)
                        })
            elif ftype == 17:
                log_with_time("ftype 17: %s" % task["url"]),
            elif ftype == 20:
                log_with_time("ftype 20: %s" % task["url"]),
    ret = [(task["crc"], promos)]
    return format_promo(ret)
Ejemplo n.º 4
0
def promo_parser(task, rule): 
    j = jsonp_json(task["text"]) 
    promos = [] 
    log_with_time("url: %s" % task["old"])
    crc = get_crc(task["old"])
    #site_enable 
    #1 客户端
    #2 手机网页
    #3 手机端 
    if not j["proms"]: 
        log_with_time("no promo: %s" % task["old"]) 
        return format_promo([(crc, promos)])
    for item in j["proms"]:
        tp = item["type"] 
        if tp == "ZENGPIN": 
            b = []
            for title in item["titleList"]:
                b.append(title["title"])
            if b:
                promos.append({
                    "keywords": "赠品",
                    "type": 3,
                    "desc": u"赠: %s" % "".join(b)
                    })
        elif tp == "LYMANZENG": 
            b = []
            for title in item["titleList"]:
                b.append(title["title"])
            if b:
                promos.append({
                    "keywords": "满赠",
                    "type": 3,
                    "desc": u"%s: %s" % (item["desc"], "".join(b))
                    }) 
        elif tp == "ZHIJIANG": 
            #ignore
            pass 
        elif tp == "ZENGQUANRED" or tp == "ZENGQUANBLUE": 
            b = []
            for title in item["titleList"]:
                b.append(u"%s张%s元%s" % (title["couponNum"], title["couponPrice"], title["couponName"])) 
            if b:
                promos.append({
                    "keywords": "赠券",
                    "type": 3,
                    "desc": u"赠: " + "".join(b)
                    }) 
        elif tp == "MANJIAN_old": 
            promos.append({
                "keywords": "满减",
                "type": 1,
                "desc": item["desc"],
                })
        elif tp == "MANJIAN": 
            promos.append({
                "keywords": "满减",
                "type": 1,
                "desc": item["desc"],
                }) 
        elif tp == "LYMANJIAN": 
            i = {
                "keywords": "满减",
                "type": 1,
                "desc": item["desc"],
                } 
            if item.get("more") or item.get("more") == "true":
                i["desc"] += item["more_msg"]
            promos.append(i) 
        elif tp == "LYMANFAN":
            promos.append({
                    "keywords": "返券",
                    "type": 2, 
                    "desc": item["desc"],
                    }) 
        elif tp == "MANFANRED": 
            desc = item["desc"].replace("&lt;", "<")
            desc = desc.replace("&gt;", ">")
            promos.append({
                    "keywords": "返券",
                    "type": 2, 
                    "desc": desc,
                    }) 
        elif tp == "ZHEKOU" or tp == "LYMANZHE": 
            promos.append({
                "keywords": "多买优惠",
                "type": 11,
                "desc": item["desc"]
                })
        #VIPPRICE -> 会员价忽略
        else:
            log_with_time("other promo: %s" % str(item))
    if not promos:
        log_with_time("no promo: %s" % task["old"]) 
    return format_promo([(crc, promos)])
Ejemplo n.º 5
0
def promo_parser(task, rule):
    promos = [] 
    if len(task["text"]) < 200: 
        log_with_time("no promo info")
        ret = [(task["crc"], promos)] 
        return format_promo(ret) 
    try:
        j = jsonp_json(task["text"])
    except ValueError:
        log_with_time("json error: %s" % task["text"]) 
        ret = [(task["crc"], promos)] 
        return format_promo(ret) 
    if not j: 
        log_with_time("json null: %s" % task["text"])
        ret = [(task["crc"], promos)] 
        return format_promo(ret) 
    if j.get("mpt"):
        price = Decimal(j.get("mpt").split(",")[0])
        promos.append({ 
            "keywords": "手机专享价",
            "type": 9,
            "desc": "手机专享价: %s" % price,
            }) 
    for i in j["promotionInfoList"]: 
        ptype = i["promoType"] 
        if i.get("addMoney") and float(i.get("addMoney")):
            continue 
        if i.get("userLevel", 0) > 50:
            continue 
        if ptype == 1:
            if not i.get("needJBeanNum"):
                i["needJBeanNum"] = 0 
            if i["needJBeanNum"] > 0 and i.get("price", 0) > 0:
                #京豆优惠购 
                promos.append({
                    "desc": "京豆优惠购",
                    "type": 11,
                    "desc": "使用%s京豆可享受优惠价%s" % (Decimal(i["needJBeanNum"]), Decimal(i["price"])) 
                    }) 
            if i.get("adwordCouponList"): 
                s = coupon(i["adwordCouponList"])
                if s:
                    promos.append({
                        "desc": "赠%s京券" % s,
                        "keywords": "赠券",
                        "type": 3,
                        })
            if i.get("score"):
                #送京豆
                promos.append({
                    "keywords": "送京豆",
                    "type": 3,
                    "desc": "送京豆%s个" % i["score"]
                    })
            if i.get("extType") == 8:
                #团购 
                promos.append({
                    "keywords": "闪团",
                    "type": 8,
                    "desc": "闪团"
                    })
        elif ptype == 15: 
            if i["rebate"] > 0: 
                promos.append({
                    "desc": "封顶",
                    "type": 11,
                    "desc": "封顶%s折" % float(10 * i["rebate"])
                    }) 
        elif ptype == 4: 
            if i.get("adwordGiftSkuList"): 
                s = []
                for m in i["adwordGiftSkuList"]:
                    #1是附件
                    if m["giftType"] == 2:
                        s.append("%s x %s" % (m["name"].replace(" ", ""), m["number"])) 
                if s:
                    promos.append({
                        "keywords": "赠品",
                        "type": 3,
                        "desc": u"赠 " + ", ".join(s)
                        })
            #赠券
            if i.get("adwordCouponList"): 
                s = coupon(i["adwordCouponList"])
                if s:
                    promos.append({
                        "desc": "赠%s京券" % s,
                        "keywords": "赠券",
                        "type": 3,
                        }) 
            #赠京豆
            if i.get("score") and float(i["score"]):
                promos.append({
                    "keywords": "送京豆",
                    "type": 3,
                    "desc": "送京豆%s个" % i["score"]
                    }) 
        elif ptype == 10: 
            ftype = i["fullRefundType"] 
            if ftype == 1: 
                for m in i["fullLadderDiscountList"]: 
                    #加价购忽略
                    if m.get("addMoney") and Decimal(m["addMoney"]): 
                        continue
                    #非满减
                    if not m["needMoney"]:
                        continue
                    m["needMoney"] = Decimal(m["needMoney"])
                    m["rewardMoney"] = Decimal(m["rewardMoney"])
                    m["percent"]  = Decimal(m.get("percent", 0))
                    if m["needMoney"] and m["rewardMoney"]:
                        promos.append({
                            "keywords": "满减",
                            "type": 1,
                            "desc": "满%s减%s" % (m["needMoney"], m["rewardMoney"]),
                            }) 
                    if m["needMoney"] and not m["rewardMoney"] and not m["percent"]:
                        promos.append({
                            "keywords": "满赠",
                            "type": 3,
                            "desc": "满%s赠热销商品" % (m["needMoney"])
                            })
                    #满赠
                    if m.get("haveFullRefundGifts"): 
                        if m["needMoney"] and ["rewardMoney"]:
                            promos.append({
                                "keywords": "满送",
                                "type": 3,
                                "desc": "满%s减%s,得赠品" % (m["needMoney"], m["rewardMoney"]),
                                }) 
                        elif m["needMoney"]:
                            promos.append({
                                "keywords": "满送",
                                "type": 3,
                                "desc": "满%s即赠热销商品" % m["needMoney"]
                                })
                    #满赠券 
                    if m.get("adwordCouponList") and i["needMoney"]: 
                        s = coupon(m["adwordCouponList"])
                        if s:
                            promos.append({
                                "keywords": "满送券",
                                "type": 3,
                                "desc": "满%s送%s京券" % (m["needMoney"], s)
                                }) 
                    if m["needMoney"] and m["percent"]: 
                        promos.append({
                            "keywords": "满%s可享折扣" % m["needMoney"],
                            "type": 1,
                            "desc": "满%s减%s%%" % (m["needMoney"], m["percent"])
                            }) 
            elif ftype == 2: 
                if not i.get("needMondey"):
                    continue
                if float(i["needMondey"]) and i["reward"]:
                    if i.get("topMoney") and float(i["topMoney"]): 
                        promos.append({
                            "desc": "多次满减",
                            "type": 1,
                            "desc": "每满%s可减%s现金, 最多可减 %s" % (Decimal(i["needMondey"]), Decimal(i["reward"]), Decimal(i["topMoney"]))
                            })
                    else:
                        promos.append({
                            "keywords": "多次满减",
                            "type": 1,
                            "desc": "每满%s可减%s现金" % (Decimal(i["needMondey"]), Decimal(i["reward"]))
                            }) 
                    if i["needMondey"] and i["adwordCouponList"]: 
                        s = coupon(i["adwordCouponList"]) 
                        if s:
                            promos.append({
                                "keywords": "满送券",
                                "type": 3,
                                "desc": "每满%s即赠%s元京券" % (Decimal(i["needMondey"]), Decimal(s))
                                }) 
            elif ftype == 6: 
                s = []
                for m in i["fullLadderDiscountList"]:
                    if Decimal(m["needMoney"]) and Decimal(m["rewardMoney"]): 
                        s.append("满%s减%s" % (Decimal(m["needMoney"]), Decimal(m["rewardMoney"])))
                if s:
                    promos.append({
                        "keywords": "满减",
                        "type": 1,
                        "desc": ", ".join(s)
                        }) 
            elif ftype == 20: 
                log_with_time("ftype 20: %s" % task["url"])
            elif ftype == 11: 
                if i["needNum"] and i["deliverNum"]:
                    promos.append({
                        "keywords": "多买多惠",
                        "type": 11,
                        "desc": "买%s立减%s件商品价格" % (i["needNum"], i["deliverNum"])
                        }) 
            elif ftype == 13: 
                if i.get("needMondey") and i.get("deliverNum"):
                    promos.append({
                        "keywords": "多件优惠",
                        "type": 11,
                        "desc": "%s元可买%s件" % (Decimal(i["needMondey"]), i["deliverNum"]),
                        }) 
            elif ftype == 14: 
                #满needNum赠热销商品
                if i.get("needNum") and i.get("rebate"):
                    promos.append({
                        "keywords": "多件优惠",
                        "type": 11,
                        "desc": "满%s件总价打%s折" % (Decimal(i["needNum"]), float(10 * i["rebate"]))
                        })
                elif i.get("needNum"): 
                    promos.append({
                        "keywords": "满赠",
                        "type": 3,
                        "desc": "满%s件即赠热销商品" % i["needNum"]
                        })
            elif ftype == 15: 
                s = []
                for m in i["fullLadderDiscountList"]:
                    if m.get("addMoney") and float(m["addMoney"]):
                        continue 
                    if m["needNum"] and m["rebate"]:
                        s.append("满%s件总价打%s折" % (m["needNum"], float(10 * m["rebate"])))
                if s:
                    promos.append({
                        "keywords": "多买优惠",
                        "type": 11,
                        "desc": ", ".join(s)
                        }) 
            elif ftype == 16: 
                mtype = i["mfmzExtType"] 
                if mtype == 0:
                    s = []
                    for m in i["fullLadderDiscountList"]: 
                        if m.get("addMoney") and float(m["addMoney"]):
                            continue
                        if m.get("needNum") and m.get("rebate"):
                            s.append("满%s件总价打%s折" % (m["needNum"],  float(10 * m["rebate"])))
                    if s:  
                        promos.append({
                            "keywords": "满减",
                            "type": 3,
                            "desc": ", ".join(s)
                            }) 
                elif mtype == 1 or mtype == 3: 
                    #fullLadderDiscountList, 阶梯满减
                    s = []
                    for m in i["fullLadderDiscountList"]:
                        if m["needMoney"] and m["rewardMoney"]: 
                            s.append("满%s减%s" % (Decimal(m["needMoney"]), Decimal(m["rewardMoney"])))
                    if s:
                        promos.append({
                            "keywords": "满减",
                            "type": 1,
                            "desc": ", ".join(s)
                            }) 
                if mtype == 2: 
                    for m in i["fullLadderDiscountList"]:
                        if m["needMoney"]:
                            promos.append({
                                "keywords": "满赠",
                                "type": 3,
                                "desc": "满%s即赠热销商品" % Decimal(m["needMoney"])
                                }) 
                elif mtype == 4: 
                    s = []
                    for m in i["fullLadderDiscountList"]:
                        if m["needMoney"]:
                            s.append("满%s得赠品" % Decimal(m["needMoney"]))
                    if s:
                        promos.append({
                            "keywords": "满赠",
                            "type": 3,
                            "desc": ",".join(s)
                            }) 
                elif mtype == 5: 
                    s = []
                    for m in i["fullLadderDiscountList"]:
                        if m["needMoney"] and m["rewardMoney"] and m["mfmzTag"] == 1:
                            s.append("满%s立减%s" % (Decimal(m["needMoney"]), Decimal(m["rewardMoney"])))
                    if s:
                        promos.append({
                            "keywords": "满减",
                            "type": 1,
                            "desc": ", ".join(s)
                            })
            elif ftype == 17:
                log_with_time("ftype 17: %s" % task["url"]),
            elif ftype == 20:
                log_with_time("ftype 20: %s" % task["url"]), 
    ret = [(task["crc"], promos)] 
    return format_promo(ret)
Ejemplo n.º 6
0
def promo_parser(task, rule):
    j = jsonp_json(task["text"])
    promos = []
    log_with_time("url: %s" % task["old"])
    crc = get_crc(task["old"])
    #site_enable
    #1 客户端
    #2 手机网页
    #3 手机端
    if not j["proms"]:
        log_with_time("no promo: %s" % task["old"])
        return format_promo([(crc, promos)])
    for item in j["proms"]:
        tp = item["type"]
        if tp == "ZENGPIN":
            b = []
            for title in item["titleList"]:
                b.append(title["title"])
            if b:
                promos.append({
                    "keywords": "赠品",
                    "type": 3,
                    "desc": u"赠: %s" % "".join(b)
                })
        elif tp == "LYMANZENG":
            b = []
            for title in item["titleList"]:
                b.append(title["title"])
            if b:
                promos.append({
                    "keywords": "满赠",
                    "type": 3,
                    "desc": u"%s: %s" % (item["desc"], "".join(b))
                })
        elif tp == "ZHIJIANG":
            #ignore
            pass
        elif tp == "ZENGQUANRED" or tp == "ZENGQUANBLUE":
            b = []
            for title in item["titleList"]:
                b.append(u"%s张%s元%s" %
                         (title["couponNum"], title["couponPrice"],
                          title["couponName"]))
            if b:
                promos.append({
                    "keywords": "赠券",
                    "type": 3,
                    "desc": u"赠: " + "".join(b)
                })
        elif tp == "MANJIAN_old":
            promos.append({
                "keywords": "满减",
                "type": 1,
                "desc": item["desc"],
            })
        elif tp == "MANJIAN":
            promos.append({
                "keywords": "满减",
                "type": 1,
                "desc": item["desc"],
            })
        elif tp == "LYMANJIAN":
            i = {
                "keywords": "满减",
                "type": 1,
                "desc": item["desc"],
            }
            if item.get("more") or item.get("more") == "true":
                i["desc"] += item["more_msg"]
            promos.append(i)
        elif tp == "LYMANFAN":
            promos.append({
                "keywords": "返券",
                "type": 2,
                "desc": item["desc"],
            })
        elif tp == "MANFANRED":
            desc = item["desc"].replace("&lt;", "<")
            desc = desc.replace("&gt;", ">")
            promos.append({
                "keywords": "返券",
                "type": 2,
                "desc": desc,
            })
        elif tp == "ZHEKOU" or tp == "LYMANZHE":
            promos.append({
                "keywords": "多买优惠",
                "type": 11,
                "desc": item["desc"]
            })
        #VIPPRICE -> 会员价忽略
        else:
            log_with_time("other promo: %s" % str(item))
    if not promos:
        log_with_time("no promo: %s" % task["old"])
    return format_promo([(crc, promos)])