Exemplo n.º 1
0
def rt_parser(items): 
    pids = get_pids(items)
    if not pids:
        log_with_time("got nothing: %s" % entries)
        return
    purl = price_url % (",".join(["J_" + i for i in pids]), 
            random.randint(1000000, 10000000), int(time.time() * 1000)) 
    surl = stock_url % (async_http.quote(",".join([i for i in pids])), 
            random.randint(1000000, 10000000), int(time.time() * 1000)) 

    price_res = simple_http.get(purl) 
    stock_res = simple_http.get(surl)
    if price_res["status"] != 200 or stock_res["status"] != 200:
        log_with_time("not200: %s" % price["res"])
        return
    try:
        price_json = jsonp_json(price_res["text"]) 
        stock_json = jsonp_json(stock_res["text"].decode("gbk"))
    except: 
        traceback.print_exc()
        return
    prices = {} 
    for i in price_json: 
        prices[i["id"].split("_")[1]] = i["p"]
    stocks = {} 
    for k,v in stock_json.items(): 
        s = v["StockStateName"]
        if u"有货" in s or u"现货" in s:
            stocks[k] = 1
        else:
            stocks[k] = 0 
    ret = []
    for pid in prices:
        ret.append((str(pid), str(prices[pid]), stocks[pid])) 
    return format_price(ret)
Exemplo n.º 2
0
def price_parser(task, rule):
    try:
        items = jsonp_json(task["text"])
    except ValueError as e:
        log_with_time("price_parser: jsonp_json: %s" % task["text"])
        return
    d = {}
    for item in items:
        d[item["id"].split("_")[1]] =  item["p"]
    return [d]
Exemplo n.º 3
0
def price_parser(task, rule):
    try:
        items = jsonp_json(task["text"])
    except ValueError as e:
        log_with_time("price_parser: jsonp_json: %s" % task["text"])
        return
    d = {}
    for item in items:
        d[item["id"].split("_")[1]] = item["p"]
    return [d]
Exemplo n.º 4
0
def pager(task, rule):
    c = task["text"].decode("utf-8")
    item = jsonp_json(c)
    if "pageBar" not in item:
        log_with_time("no pageBar: %s" % task["url"])
        return
    m = item["pageBar"]
    ret = []
    if not m.get("totalCount", 0):
        log_with_time("empty category: %s" % task["url"])
        return ret
    for i in range(1, m["totalPage"] + 1):
        ret.append({"url": payload(task['cat'], i)})
    return ret
Exemplo n.º 5
0
def rt_parser(items):
    pids = get_pids(items)
    if not pids:
        log_with_time("got nothing: %s" % entries)
        return
    purl = price_url % (",".join([
        "J_" + i for i in pids
    ]), random.randint(1000000, 10000000), int(time.time() * 1000))
    surl = stock_url % (async_http.quote(",".join([
        i for i in pids
    ])), random.randint(1000000, 10000000), int(time.time() * 1000))

    price_res = simple_http.get(purl)
    stock_res = simple_http.get(surl)
    if price_res["status"] != 200 or stock_res["status"] != 200:
        log_with_time("not200: %s" % price["res"])
        return
    try:
        price_json = jsonp_json(price_res["text"])
        stock_json = jsonp_json(stock_res["text"].decode("gbk"))
    except:
        traceback.print_exc()
        return
    prices = {}
    for i in price_json:
        prices[i["id"].split("_")[1]] = i["p"]
    stocks = {}
    for k, v in stock_json.items():
        s = v["StockStateName"]
        if u"有货" in s or u"现货" in s:
            stocks[k] = 1
        else:
            stocks[k] = 0
    ret = []
    for pid in prices:
        ret.append((str(pid), str(prices[pid]), stocks[pid]))
    return format_price(ret)
Exemplo n.º 6
0
def pager(task, rule): 
    c = task["text"].decode("utf-8")
    item = jsonp_json(c)
    if "pageBar" not in item:
        log_with_time("no pageBar: %s" % task["url"])
        return
    m = item["pageBar"]
    ret = [] 
    if not m.get("totalCount", 0):
        log_with_time("empty category: %s" % task["url"])
        return ret 
    for i in range(1, m["totalPage"]+1): 
        ret.append({ 
            "url": payload(task['cat'], i)
            }) 
    return ret
Exemplo n.º 7
0
def stock_parser(task, rule): 
    try:
        j = jsonp_json(task["text"].decode("utf-8"))
    except Exception as e:
        log_with_time("response error: %s %s" % (task["url"], e)) 
        return 
    ret= [] 
    for item in j.get("PromPriceList", []): 
        pid = str(item["ProductId"])
        price = item["PromPriceShow"] 
        if item["Stock"]:
            stock = 1
        else:
            stock = 0 
        ret.append((pid, str(price), stock)) 
    return format_price(ret)
Exemplo n.º 8
0
def stock_parser(task, rule):
    try: 
        nodes = jsonp_json(task["text"].decode("gbk"))["result"] 
    except:
        log_with_time("bad response %s"%task['url'])
        return
    ret = []
    for i in nodes:
        gid = i['id']
        try:
            price = i['price']['buyPrice']['priceValue']
        except:
            price = -1
        stock = 1 if i['sellable'] else 0
        ret.append((str(itemurl%gid), str(price), stock))
    fret = format_price(ret)
    return fret
Exemplo n.º 9
0
def list_parser(task, rule):
    try:
        j = jsonp_json(task["text"].decode("utf-8"))
        t = etree.HTML(j['value'])
    except Exception as e:
        import traceback
        traceback.print_exc()
        exit(1)
    ret = []
    dps = {}
    dp = []
    comments = {}
    shop = {}
    #dp, comment, shopid, price
    nodes = t.xpath(rule['node'])
    now = int(time.time())
    for node in nodes:
        price = node.xpath(rule["price"])
        if not price:
            log_with_time("price rule error: %s" % task["url"])
            continue
        price = price[0]
        gid = re.findall("_([0-9]+)", node.attrib["id"])[0]
        comment = node.xpath(rule["comment"])
        if comment:
            comments[gid] = re.findall("\d+", "".join(comment))[0]
        shop_link = node.xpath(rule["shop"])
        if shop_link:
            shop_link = shop_link[0]
            store_id = re.findall("/m-([0-9]+)\.",
                                  shop_link.attrib.get("href"))[0]
            shop[gid] = "%s,%s" % (store_id, shop_link.attrib.get("title"))
        ret.append((gid, price))
        dps[gid] = now
        pmids = node.xpath(rule["link"])
        if not pmids:
            log_with_time("dp rule error: %s" % task["url"])
            continue
        dp.append((dp_base % pmids[0], gid, ""))
    return {
        "stock": ret,
        "dps": dps,
        "comment": comments,
        "shop": shop,
        "dp": dp,
    }
Exemplo n.º 10
0
def stock_parser(task, rule):
    try:
        nodes = jsonp_json(task["text"].decode("gbk"))["result"]
    except:
        log_with_time("bad response %s" % task['url'])
        return
    ret = []
    for i in nodes:
        gid = i['id']
        try:
            price = i['price']['buyPrice']['priceValue']
        except:
            price = -1
        stock = 1 if i['sellable'] else 0
        ret.append((str(itemurl % gid), str(price), stock))
    fret = format_price(ret)
    return fret
Exemplo n.º 11
0
def list_parser(task, rule): 
    try:
        j = jsonp_json(task["text"].decode("utf-8"))
        t = etree.HTML(j['value'])
    except Exception as e:
        import traceback
        traceback.print_exc() 
        exit(1)
    ret = []
    dps = {}
    dp = []
    comments = {}
    shop = {}
    #dp, comment, shopid, price
    nodes = t.xpath(rule['node']) 
    now = int(time.time()) 
    for node in nodes: 
        price = node.xpath(rule["price"]) 
        if not price:
            log_with_time("price rule error: %s" % task["url"])
            continue
        price = price[0]
        gid = re.findall("_([0-9]+)", node.attrib["id"])[0] 
        comment = node.xpath(rule["comment"]) 
        if comment: 
            comments[gid] = re.findall("\d+", "".join(comment))[0]
        shop_link = node.xpath(rule["shop"]) 
        if shop_link: 
            shop_link = shop_link[0]
            store_id = re.findall("/m-([0-9]+)\.", shop_link.attrib.get("href"))[0] 
            shop[gid] = "%s,%s" % (store_id, shop_link.attrib.get("title")) 
        ret.append((gid, price))
        dps[gid] = now
        pmids = node.xpath(rule["link"])
        if not pmids:
            log_with_time("dp rule error: %s" % task["url"])
            continue
        dp.append((dp_base % pmids[0], gid, "")) 
    return {
            "stock":ret,
            "dps":dps,
            "comment": comments,
            "shop": shop,
            "dp": dp,
            } 
Exemplo n.º 12
0
def list_parser(task, rule): 
    item = jsonp_json(task["text"]) 
    skus = [] 
    groups = [] 
    dp_pairs = [] 
    if "products" not in item: 
        log_with_time("found nothing: %s" % task["url"])
        return
    now = int(time.time())
    dps_log = {} 
    shop = {}
    comment = {}
    promos = []
    for p in item["products"]: 
        try: 
            s = p["skus"] 
            price = str(s["price"])
            url = str(s["sUrl"])
            title = s["name"]
        except KeyError:
            log_with_time("rule error: %s" % task["text"])
            continue 
        dp_pairs.append((url, title))
        if s["stock"] > 0:
            stock = 1
        else:
            stock = 0 
        promos.append((url, s["skuNo"]))
        skus.append((url, price, stock)) 
        if p.get("shopId"):
            shop[get_crc(url)] =  "%s,%s" % (p["shopId"], p["sName"])
        if p.get("evaluateCount"): 
            comment[get_crc(url)] = int(p["evaluateCount"])
    result = format_price(skus) 
    for r in result:
        dps_log[r[1]] = now 
    return {
            "spider": result,
            "dp": dp_pairs,
            "dps_log": dps_log,
            "shop": shop,
            "comment": comment,
            "promo": promos,
            }
Exemplo n.º 13
0
def list_parser(task, rule):
    item = jsonp_json(task["text"])
    skus = []
    groups = []
    dp_pairs = []
    if "products" not in item:
        log_with_time("found nothing: %s" % task["url"])
        return
    now = int(time.time())
    dps_log = {}
    shop = {}
    comment = {}
    promos = []
    for p in item["products"]:
        try:
            s = p["skus"]
            price = str(s["price"])
            url = str(s["sUrl"])
            title = s["name"]
        except KeyError:
            log_with_time("rule error: %s" % task["text"])
            continue
        dp_pairs.append((url, title))
        if s["stock"] > 0:
            stock = 1
        else:
            stock = 0
        promos.append((url, s["skuNo"]))
        skus.append((url, price, stock))
        if p.get("shopId"):
            shop[get_crc(url)] = "%s,%s" % (p["shopId"], p["sName"])
        if p.get("evaluateCount"):
            comment[get_crc(url)] = int(p["evaluateCount"])
    result = format_price(skus)
    for r in result:
        dps_log[r[1]] = now
    return {
        "spider": result,
        "dp": dp_pairs,
        "dps_log": dps_log,
        "shop": shop,
        "comment": comment,
        "promo": promos,
    }
Exemplo n.º 14
0
def stock_parser(task, rule):
    try:
        stock = jsonp_json(task["text"].decode("gbk"))
    except ValueError as e:
        log_with_time("stock_parser: jsonp_json: %s" % task["text"])
        return
    stocks = {}
    for key,value in stock.items():
        s = value["StockStateName"]
        if u"现货" in s or u"有货" in s:
            stocks[key] = 1
        else:
            stocks[key] = 0
    ret = []
    prices = task["price"]
    for key,price in prices.items():
        if key not in stocks:
            log_with_time("key not in stocks: %s" % task["url"])
            continue
        ret.append((key, price, stocks[key]))
    result = format_price(ret) 
    return result
Exemplo n.º 15
0
def stock_parser(task, rule):
    try:
        stock = jsonp_json(task["text"].decode("gbk"))
    except ValueError as e:
        log_with_time("stock_parser: jsonp_json: %s" % task["text"])
        return
    stocks = {}
    for key, value in stock.items():
        s = value["StockStateName"]
        if u"现货" in s or u"有货" in s:
            stocks[key] = 1
        else:
            stocks[key] = 0
    ret = []
    prices = task["price"]
    for key, price in prices.items():
        if key not in stocks:
            log_with_time("key not in stocks: %s" % task["url"])
            continue
        ret.append((key, price, stocks[key]))
    result = format_price(ret)
    return result
Exemplo n.º 16
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)
Exemplo n.º 17
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)
Exemplo n.º 18
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)])
Exemplo n.º 19
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)])