예제 #1
0
파일: tb.py 프로젝트: yezamber/youxiang
def tb_share_text(group_name: str, material_id: str, app_key, app_secret,
                  adzone_id):
    '''

    :param group_name:
    :param material_id:
    :return:
    '''
    try:
        material_id = str(random.choices(material_id.split(','))[0])
        print(material_id)
        groups = itchat.search_chatrooms(name=f'''{group_name}''')
        for room in groups:
            group_name = room['UserName']
            time.sleep(random.randint(1, 5))
            tb_client = TbApiClient(app_key=app_key,
                                    secret_key=app_secret,
                                    adzone_id=adzone_id)
            res = tb_client.taobao_tbk_dg_optimus_material(material_id)
            json_data = json.loads(res)['tbk_dg_optimus_material_response'][
                'result_list']['map_data']
            count = 0
            for item in json_data:
                count += 1
                if str(item).find("coupon_share_url") > -1:
                    coupon_share_url = "https:" + item['coupon_share_url']
                    coupon_amount = item['coupon_amount']
                    pict_url = "https:" + str(item['pict_url'])
                    title = item['title']
                    item_id = item['item_id']
                    filename = save_pic(pict_url, item_id)
                    zk_final_price = item['zk_final_price']
                    # 发送图片
                    itchat.send('@img@%s' % (f'''{filename}'''), group_name)

                    itchat.send(
                        f''' {title} \n【在售价】¥{zk_final_price}\n【券后价】¥{round(float(zk_final_price) - float(coupon_amount),
                                                                             2)}\n-----------------\n復製評论({tb_client.taobao_tbk_tpwd_create(
                        title, coupon_share_url)}),去【tao寶】下单\n''', group_name)

                    time.sleep(2)
                    del_pic(filename)
                else:
                    click_url = "https:" + item['click_url']
                    title = item['title']
                    item_id = item['item_id']
                    pict_url = "https:" + str(item['pict_url'])
                    zk_final_price = item['zk_final_price']
                    print(pict_url)
                    filename = save_pic(pict_url, item_id)
                    itchat.send('@img@%s' % (f'''{filename}'''), group_name)
                    itchat.send(
                        f'''{title} \n【在售价】¥{zk_final_price}\n-----------------\n復製評论({tb_client.taobao_tbk_tpwd_create(
                            title, click_url)}),去【tao寶】下单\n''', group_name)
                    time.sleep(2)
                    del_pic(filename)
    except Exception as e:
        print(e)
        tb_share_text(group_name, material_id, app_key, app_secret, adzone_id)
예제 #2
0
파일: pdd.py 프로젝트: zenozhengs/youxiang
def pdd_share_text(group_name: str, group_material_id: str, app_key: str,
                   secret_key: str, p_id: str):
    '''
    :param group_name:
    :param material_id:
    :return:
    '''
    try:
        offset = str(random.randint(1, 295))  # top.goods.list.query 好像只有300个商品
        limit = str(random.randint(3, 5))  #

        client = PddApiClient(app_key=app_key, secret_key=secret_key)
        resp = client.call("pdd.ddk.top.goods.list.query", {
            "offset": offset,
            "limit": limit,
            "p_id": p_id
        })
    except Exception as e:
        print(e)
        set_system_notice(f'''offset: {offset},\nlimit:{limit}\n\n发现问题''')
        pdd_share_text(group_name, group_material_id, app_key, secret_key,
                       secret_key, p_id)

    for data in json.loads(resp.text)['top_goods_list_get_response']['list']:
        goods_id = data['goods_id']
        goods_name = data['goods_name']
        search_id = data['search_id']
        goods_thumbnail_url = data['goods_thumbnail_url']
        min_normal_price = int(data['min_normal_price'])  # 原价
        min_group_price = int(data['min_group_price'])  # 折扣价
        coupon_discount = int(data['coupon_discount'])  # 券价
        if min_group_price < min_normal_price:
            cal_price = min_group_price
        else:
            cal_price = min_normal_price
        cal_price_str = str(cal_price)[:len(str(cal_price)) - 2] if len(
            str(cal_price)[:len(str(cal_price)) - 2]
        ) > 0 else '0' + '.' + str(cal_price)[len(str(cal_price)) - 2:]
        price = str(cal_price - coupon_discount)[:len(str(cal_price - coupon_discount))-2] \
            if len(str(cal_price - coupon_discount)[:len(str(cal_price - coupon_discount))-2]) > 0 else '0'+ '.' \
                + str(cal_price - coupon_discount)[len(str(cal_price - coupon_discount))-2:]
        short_url = promotion_url_generate(app_key=app_key,
                                           secret_key=secret_key,
                                           p_id=p_id,
                                           goods_id_list=int(goods_id),
                                           search_id=search_id)

        groups = itchat.search_chatrooms(name=f'''{group_name}''')
        for room in groups:
            room_name = room['UserName']
            time.sleep(random.randint(1, 5))
            filename = save_pic(goods_thumbnail_url, goods_id)
            # 发送图片
            itchat.send('@img@%s' % (f'''{filename}'''), room_name)
            time.sleep(random.randint(1, 3))
            itchat.send(
                f''' {goods_name} \n【现价】¥{cal_price_str}\n【内部价】¥{price}\n-----------------\n抢购地址:\n{short_url}''',
                room_name)
            del_pic(filename)
예제 #3
0
def handle_group_pictures(msg):
    '''
    :return:
    '''

    # 自己通过手机微信发送给别人的消息(文件传输助手除外)不作处理。
    if msg['FromUserName'] == config.get('wechat_uuid') and msg['ToUserName'] != FILEHELPER:
        return
    # 判断是否来自指定群
    uuid = msg.fromUserName  # 群 uid
    # print(f'''这个群聊的id是{uuid}''')
    # ated_uuid = msg.actualUserName  # 发送人的用户uuid
    # ated_name = msg.actualNickName  # 发送人群里的名称
    # file_name = msg['FileName'] # 文件默认文件名
    msg.download(msg.fileName)
    if is_white_group(uuid):
        if QRcode_detection(msg.fileName):
            itchat.delete_member_from_chatroom(msg.FromUserName, [{'UserName': msg.ActualUserName}])
    del_pic(msg.fileName)
예제 #4
0
파일: sn.py 프로젝트: zenozhengs/youxiang
def sn_share_text(group_name: str, group_material_id: str, app_key:str, secret_key:str, ad_book_id: str):
    '''
    :param group_name:
    :param material_id:
    :return:
    '''
    try:
        offset = str(random.randint(1, 71))
        limit = str(random.randint(5, 10))
        print(f'''offset:{offset},limit:{limit}''')
        client = api.RecommendcommodityQueryRequest()
        client.setDomainInfo("open.suning.com", "80")
        client.setAppInfo(app_key, secret_key)
        client.couponMark = '1'
        client.pageIndex = offset
        client.size = limit
        resp = client.getResponse()['sn_responseContent']['sn_body']['queryRecommendcommodity']
        for data in resp:
            title = data['commodityInfo']['commodityName'] # 商品名称
            commodityCode = data['commodityInfo']['commodityCode'] # 商品编码
            supplierCode = data['commodityInfo']['supplierCode'] # 店铺编码
            sellingPoint = data['commodityInfo']['sellingPoint'] # 卖点
            snPrice = data['commodityInfo']['snPrice'] # 原价
            commodityPrice = data['commodityInfo']['commodityPrice'] # 内部价
            baoyou = data['commodityInfo']['baoyou'] # 内部价
            if baoyou == 1:
                sellingPoint = f'''包邮 {sellingPoint} '''
            images_count = 0
            for image in data['commodityInfo']['pictureUrl']:
                images_count += 1
                if images_count > 3:  ## 3个以上图片就不发了
                    pass
                else:
                    image_url = image['picUrl'].replace('_200w_200h_4e','')
                    print(image_url)
                    groups = itchat.search_chatrooms(name=f'''{group_name}''')
                    for room in groups:
                        room_name = room['UserName']
                        time.sleep(random.randint(5, 10))
                        filename = save_pic(image_url, commodityCode)
                        itchat.send('@img@%s' % (f'''{filename}'''), room_name)
                    del_pic(filename)

            pgPrice = data['pgInfo']['pgPrice'] # 拼购价
            pgNum = data['pgInfo']['pgNum'] # 拼购价

            couponValue = data['couponInfo']['couponValue'] # 优惠券面额
            bounsLimit = data['couponInfo']['bounsLimit'] # 使用下限(满多少可用)
            afterCouponPrice = data['couponInfo']['afterCouponPrice'] # 使用下限(满多少可用)

            sn_share_url = promotion_url_generate(app_key, secret_key, ad_book_id, commodityCode, supplierCode.zfill(10))

            if pgPrice == '': #不是拼购单
                if couponValue == '': # 没有券
                    if float(snPrice) == float(commodityPrice):
                        share_text = f'''{sellingPoint}\n【苏宁】{title}\n——————————\n 【爆款价】¥{commodityPrice}\n抢购地址:\n{sn_share_url}'''
                    else:
                        share_text = f'''{sellingPoint}\n【苏宁】{title}\n——————————\n 【原价】¥{snPrice}\n【爆款价】¥{commodityPrice}\n抢购地址:\n{sn_share_url}'''
                else: # 有券
                    bounsLimit = float(bounsLimit)
                    couponValue = float(couponValue)
                    commodityPrice = float(commodityPrice)
                    if commodityPrice >= bounsLimit: # 如果商品满足满用券下限
                        if float(snPrice) == float(commodityPrice):
                            share_text = f'''{sellingPoint}\n【苏宁】{title}\n领券再减{data['couponInfo']['couponValue']}元!\n——————————\n 【券后内部价】¥{round(float(commodityPrice-couponValue),2)}\n抢购地址:\n{sn_share_url}'''
                        else:
                            share_text = f'''{sellingPoint}\n【苏宁】{title}\n领券再减{data['couponInfo']['couponValue']}元!\n——————————\n 【原价】¥{snPrice}\n【券后内部价】¥{round(float(commodityPrice-couponValue),2)}\n抢购地址:\n{sn_share_url}'''
                    else:
                        buy_count = int(bounsLimit // commodityPrice + 1)
                        if float(snPrice) == float(commodityPrice):
                            if float(commodityPrice)*buy_count - float(data['couponInfo']['couponValue']) <=0:
                                share_text = f'''{sellingPoint}\n【苏宁】{title}\n——————————\n 【爆款价】¥{afterCouponPrice}\n部分地区用户可领券再减,以实际优惠为准![哇][哇]\n抢购地址:\n{sn_share_url}'''
                            else:
                                share_text = f'''{sellingPoint}\n【苏宁】{title}\n——————————\n 【爆款价】¥{commodityPrice}\n拍{buy_count}件,用券再减{data['couponInfo']['couponValue']}元!{buy_count}件约{round(float(commodityPrice)*buy_count - float(data['couponInfo']['couponValue']),2)}元!\n抢购地址:\n{sn_share_url}'''

                        else:
                            if float(commodityPrice) * buy_count - float(data['couponInfo']['couponValue']) <= 0:
                                share_text = f'''{sellingPoint}\n【苏宁】{title}\n——————————\n 【原价】¥{snPrice}\n【爆款价】¥{afterCouponPrice}\n部分地区用户可领券再减,具体以实际优惠为准![哇][哇]\n抢购地址:\n{sn_share_url}'''
                            else:
                                share_text = f'''{sellingPoint}\n【苏宁】{title}\n——————————\n 【原价】¥{snPrice}\n【爆款价】¥{commodityPrice}\n拍{buy_count}件,用券再减{data['couponInfo']['couponValue']}元!{buy_count}件约{round(float(commodityPrice)*buy_count - float(data['couponInfo']['couponValue']),2)}元!\n抢购地址:\n{sn_share_url}'''
            else: # 拼购单
                if couponValue == '': # 没有券
                    if float(snPrice) == float(commodityPrice):
                        share_text = f'''{sellingPoint}\n【苏宁{pgNum}人拼购】{title}\n——————————\n 【拼购价】¥{pgPrice}\n抢购地址:\n{sn_share_url}'''
                    else:
                        share_text = f'''{sellingPoint}\n【苏宁{pgNum}人拼购】{title}\n——————————\n 【原价】¥{snPrice}\n【拼购价】¥{pgPrice}\n抢购地址:\n{sn_share_url}'''
                else: # 有券
                    bounsLimit = float(bounsLimit)
                    pgPrice = float(pgPrice)
                    if pgPrice >= bounsLimit:# 如果拼购价格满足满用券下限
                        if float(snPrice) == float(pgPrice):
                            share_text = f'''{sellingPoint}\n【苏宁{pgNum}人拼购】{title}\n领券再减{data['couponInfo']['couponValue']}元!\n——————————\n 【券后拼购价】¥{pgPrice}\n抢购地址:\n{sn_share_url}'''
                        else:
                            share_text = f'''{sellingPoint}\n【苏宁{pgNum}人拼购】{title}\n领券再减{data['couponInfo']['couponValue']}元!\n——————————\n 【原价】¥{snPrice}\n【券后拼购价】¥{pgPrice}\n抢购地址:\n{sn_share_url}'''
                    else:
                        buy_count = int(bounsLimit // pgPrice + 1)
                        if float(snPrice) == float(commodityPrice):
                            if float(commodityPrice) * buy_count - float(data['couponInfo']['couponValue']) <= 0:
                                share_text = f'''{sellingPoint}\n【苏宁{pgNum}人拼购】{title}\n——————————\n 【爆款价】¥{afterCouponPrice}\n部分地区用户可领券再减,以实际优惠为准![哇][哇]\n抢购地址:\n{sn_share_url}'''
                            else:
                                share_text = f'''{sellingPoint}\n【苏宁{pgNum}人拼购】{title}\n——————————\n 【爆款价】¥{commodityPrice}\n拍{buy_count}件,用券再减{data['couponInfo']['couponValue']}元!{buy_count}件约{round(float(commodityPrice)*buy_count - float(data['couponInfo']['couponValue']),2)}元!\n抢购地址:\n{sn_share_url}'''
                        else:
                            if float(commodityPrice) * buy_count - float(data['couponInfo']['couponValue']) <= 0:
                                share_text = f'''{sellingPoint}\n【苏宁{pgNum}人拼购】{title}\n——————————\n 【原价】¥{snPrice}\n【爆款价】¥{afterCouponPrice}\n部分地区用户可领券再减,以实际优惠为准![哇][哇]\n抢购地址:\n{sn_share_url}'''
                            else:
                                share_text = f'''{sellingPoint}\n【苏宁{pgNum}人拼购】{title}\n——————————\n 【原价】¥{snPrice}\n【爆款价】¥{commodityPrice}\n拍{buy_count}件,用券再减{data['couponInfo']['couponValue']}元!{buy_count}件约{round(float(commodityPrice)*buy_count - float(data['couponInfo']['couponValue']),2)}元!\n抢购地址:\n{sn_share_url}'''

            groups = itchat.search_chatrooms(name=f'''{group_name}''')
            for room in groups:
                room_name = room['UserName']
                time.sleep(random.randint(3, 5))
                print(share_text)
                itchat.send(share_text, room_name)

    except Exception as e:
        print(e)
        set_system_notice(f'''苏宁:offset: {offset},\nlimit:{limit}\n\n发现问题''')
        sn_share_text(group_name, group_material_id, app_key, secret_key, ad_book_id)
예제 #5
0
파일: jd.py 프로젝트: zenozhengs/youxiang
def jingfen_query(group_name: str, group_material_id: str, app_key: str,
                  secret_key: str, site_id: str, suo_mi_token: str):
    ''' 方法效率不咋地,不管了
    https://union.jd.com/openplatform/api/10421
    :return:
    '''
    info = []
    try:
        page_no = str(random.randint(1, 25))
        page_size = str(random.randint(3, 5))  # 不建议发很多,图片接口会跪

        client = JdApiClient(app_key=app_key, secret_key=secret_key)
        resp = client.call(
            "jd.union.open.goods.jingfen.query", {
                "goodsReq": {
                    "sort": "desc",
                    "pageSize": page_size,
                    "pageIndex": page_no,
                    "eliteId": group_material_id
                }
            })
    except Exception as e:
        print(e)
        set_system_notice(
            f'''page_no: {page_no},\npage_size:{page_size}\n, eliteId:{group_material_id}\n发现问题'''
        )
        jingfen_query(group_name, group_material_id, app_key, secret_key,
                      site_id, suo_mi_token)

    # pprint.pprint(json.loads(resp.json()['jd_union_open_goods_jingfen_query_response']['result']))
    for data in json.loads(
            resp.json()['jd_union_open_goods_jingfen_query_response']
        ['result'])['data']:
        print(data)
        sku_name = data['skuName']  ## 商品全名
        sku_id = data['skuId']  ## 商品 sku
        material_url = f'''http://{(data['materialUrl'])}'''  ## 商品url

        couponInfos = data['couponInfo']  ## 优惠券列表
        # 查找最优优惠券
        coupon_link = ""
        discount = 0
        share_text = ""
        lowest_price_type = data['priceInfo']['lowestPriceType']  ## 什么类型
        is_coupon = False
        for couponInfo in couponInfos['couponList']:
            if 'isBest' in couponInfo:
                if int(couponInfo['isBest']) == 1:
                    discount = couponInfo['discount']  ## 优惠券额度
                    coupon_link = couponInfo['link']  ## 优惠券领取地址
                    is_coupon = True
            else:
                discount = couponInfo['discount']  ## 优惠券额度
                coupon_link = couponInfo['link']  ## 优惠券领取地址
                is_coupon = True

        if is_coupon:  # 如果有券
            if lowest_price_type == 3:  # 秒杀
                price = data['seckillInfo']['seckillOriPrice']  # 原价
                lowest_price = data['priceInfo']['lowestCouponPrice']  # 秒杀价
                duanzhi = tb_share_text(app_key, secret_key, material_url,
                                        coupon_link, site_id, suo_mi_token)
                share_text = f'''【秒杀】{sku_name}\n——————————\n  【原价】¥{price}\n 【券后秒杀价】¥{lowest_price}\n抢购地址:{duanzhi}'''
            elif lowest_price_type == 2:  # 拼购
                price = data['priceInfo']['price']  # 原价
                lowest_price = data['priceInfo']['lowestCouponPrice']  # 用券拼购
                duanzhi = tb_share_text(app_key, secret_key, material_url,
                                        coupon_link, site_id, suo_mi_token)
                share_text = f'''【拼购】{sku_name}\n——————————\n  【原价】¥{price}\n 【券后拼购价】¥{lowest_price}\n抢购地址:{duanzhi}'''
            else:
                price = data['priceInfo']['price']  ## 商品价格
                lowest_price = data['priceInfo']['lowestCouponPrice']
                duanzhi = tb_share_text(app_key, secret_key, material_url,
                                        coupon_link, site_id, suo_mi_token)
                share_text = f'''【京东】{sku_name}\n——————————\n  【爆款价】¥{price}\n 【用卷价】¥{lowest_price}\n抢购地址:{duanzhi}'''

        else:  ## 如果没有券
            if lowest_price_type == 3:  # 秒杀
                price = data['seckillInfo']['seckillOriPrice']  # 原价
                lowest_price = data['seckillInfo']['seckillPrice']  # 秒杀价
                duanzhi = tb_share_text(app_key, secret_key, material_url,
                                        coupon_link, site_id, suo_mi_token)
                share_text = f'''【秒杀】{sku_name}\n——————————\n  【原价】¥{price}\n 【秒杀价】¥{lowest_price}\n抢购地址:{duanzhi}'''

            elif lowest_price_type == 2:  # 拼购
                price = data['priceInfo']['price']  # 原价
                lowest_price = data['priceInfo']['lowestPrice']  # 用券拼购
                duanzhi = tb_share_text(app_key, secret_key, material_url,
                                        coupon_link, site_id, suo_mi_token)
                share_text = f'''【拼购】{sku_name}\n——————————\n  【原价】¥{price}\n 【拼购价】¥{lowest_price}\n抢购地址:{duanzhi}'''
            else:
                lowest_price = data['priceInfo']['price']
                # 得到短址
                duanzhi = tb_share_text(app_key, secret_key, material_url,
                                        coupon_link, site_id, suo_mi_token)
                share_text = f'''【京东】{sku_name}\n——————————\n 【爆款价】¥{lowest_price}\n抢购地址:{duanzhi}'''

        ## 获取 images
        image_list = []
        images_count = 0
        for image in data['imageInfo']['imageList']:
            images_count += 1
            if images_count > 3:  ## 3个以上图片就不发了
                pass
            else:
                image_url = image['url']
                filename = save_pic(image_url, sku_id)
                groups = itchat.search_chatrooms(name=f'''{group_name}''')
                for room in groups:
                    room_name = room['UserName']
                    time.sleep(random.randint(5, 10))
                    itchat.send('@img@%s' % (f'''{filename}'''), room_name)
                del_pic(filename)
                # print(image_url)

        groups = itchat.search_chatrooms(name=f'''{group_name}''')
        for room in groups:
            room_name = room['UserName']
            time.sleep(random.randint(3, 5))
            itchat.send(share_text, room_name)