def test(self):
        requests_cookie_jar = self.__cookie_service.load(account=self.account)

        context = Context()
        context.attach(Context.KEY_IS_UPDATE_COOKIES, True)
        context.attach(Context.KEY_HEADERS, SpiderHttp.get_taobao_headers('https://s.m.taobao.com/h5'))
        context.attach(Context.KEY_COOKIES, requests_cookie_jar)
        context.attach(Context.KEY_CURRENT_TASK_ACCOUNT, self.account)
        proxy = self.__proxy_service.get_s_proxy(self.account['username'])
        context.attach(Context.KEY_CURRENT_PROXY, proxy)

        good = Good()
        good.set_brand_name('Flyco/飞科')
        good.set_model_name('FR5218')
        context.attach(Context.KEY_GOOD_DICT, good)

        action = TaobaoPresearchAction()
        action.execute(context=context)
        try:
            # action = TaobaoBaichuanAction()
            # action.execute(context=context)
            action = TaobaoSaleListPageAction()
            action.execute(context=context)
        except CookieNeedUpdateException as e:
            self.__cookie_service.dump(requests_cookie_jar, self.account)
Example #2
0
    def do_execute(self, context):
        account = context.get(Context.KEY_CURRENT_TASK_ACCOUNT)
        # brands_result = context.get(Context.KEY_SYCM_PRODUCT_GET_BRANDS_RESULT)
        hot_rank_result = context.get(
            Context.KEY_SYCM_PRODUCT_PROD_HOT_RANK_RESULT)
        hot_rank_result = hot_rank_result['data']
        task = context.get(Context.KEY_CURRENT_TASK)
        with write_session_scope() as session:
            good = context.get(Context.KEY_GOOD_DICT)
            stream_opt_data_dao = get_stream_opt_data_dao(session=session)
            stream_unhandle_task_dao = get_stream_unhandle_task_dao(
                session=session)
            stream_handle_task_dao = get_stream_handle_task_dao(
                session=session)
            opt_data_entity = {
                'raw_data': {
                    'hotRankResult': hot_rank_result,
                    'goodResult': good
                },
                'type': int(TaobaoPageType.sycm_list)
            }
            entity = stream_opt_data_dao.insert(**opt_data_entity)

            unhandle_task_entities = []
            for item in hot_rank_result:
                c_good = Good(deepcopy(good))
                c_good.set_brand_id(item['brandId'])
                c_good.set_brand_name(item['brandName'])
                c_good.set_model_id(item['modelId'])
                c_good.set_model_name(item['modelName'])
                c_good.set_sell_count(item['payItmCnt'])
                unhandle_task_entities.append({
                    'raw_data': {
                        'hotRankInfo': item,
                        'goodResult': c_good,
                        'account': account
                    },
                    'type':
                    int(TaobaoTaskType.sycm_list),
                    'origin_id':
                    entity.id,
                    'date':
                    good['date']
                })
            stream_unhandle_task_dao.bulk_insert(unhandle_task_entities)
            entity = stream_unhandle_task_dao.delete(
                _filter=[CmmSysStreamUnhandleTask.id == task.id])
            stream_handle_task_dao.insert(
                **{
                    'type': task.type,
                    'raw_data': task.raw_data,
                    'origin_id': task.origin_id,
                    'date': good['date']
                })
        return True