Beispiel #1
0
def get_ztk_api_v2(logger: Optional[structlog.stdlib.BoundLogger] = None):
    if logger is None:
        logger = get_logger()
    global g_ztk
    if g_ztk is None:
        g_ztk = ZTKStd(SConfig.ZTKSid, logger)
    return g_ztk
Beispiel #2
0
async def get_ztk_std_api(
        logger: Optional[structlog.stdlib.BoundLogger] = None):
    if logger is None:
        logger = get_logger()

    sid = await SConfig.async_ztk_sid()
    return ZTKStd(ztk_sid=sid, logger=logger)
Beispiel #3
0
    async def gao_yong(self, args: GaoYongArgs) -> Optional[TbkItemInfo]:
        """
        高佣转换

        :param args:
        :return:
        """
        ztk = ZTKStd(await SConfig.async_ztk_sid(), self._log)
        ret = await ztk.gao_yong(args)
        return ret
    async def get_data_list_tkl(tkl: str, sid: str, ali_pid: str,
                                logger: BoundLogger) -> List[TbkItemInfo]:
        ztk = ZTKStd(sid, logger=logger)
        args = TKLParseArgs(content=tkl, sid=sid)
        tao_id = await ztk.tkl_parse(args)
        if tao_id is None:
            return []

        args = GaoYongArgs(pid=ali_pid, num_iid=tao_id, sid=sid)
        ret = await ztk.gao_yong(args)
        if ret is None:
            return []
        return [ret]
Beispiel #5
0
    def get(self, request: HttpRequest, *args, **kwargs):
        logger = get_logger("django")

        form = SearchForm(request.GET)
        if not form.is_valid():
            logger.error(f"form is invalid, {request.GET=}")
            return redirect("/")

        data = form.cleaned_data
        name = data["name"]
        page = data["page"]
        if not isinstance(page, int):
            page = 1
        ztk = ZTKStd(SConfig.ZTKSid, logger=logger)
        args = SearchArgs(q=name, page=page)
        ret = async_to_sync(ztk.search)(args)
        return self.render_to_response(
            super().get_context_data(
                data_list=ret, page=page, args=args, form=form, **kwargs
            )
        )
Beispiel #6
0
    def get_context_data(self, **kwargs):
        page = int(self.request.GET.get("page", 1))

        name = self.request.GET.get("name", None)

        assert isinstance(self.request, HttpRequest)
        logger = get_logger("django")

        args = GuessYouLikeArgs(**self.request.GET.dict())  # noqa

        ztk = ZTKStd(SConfig.ZTKSid, logger)
        ret = async_to_sync(ztk.guess_you_like)(args)

        show_coupon = SConfig.WEB_SHOW_COUPON

        return super().get_context_data(
            data_list=ret,
            show_coupon=show_coupon,
            page=page,
            name=name,
            args=args,
            **kwargs
        )
Beispiel #7
0
def get_ztk_api_v2(logger: structlog.stdlib.BoundLogger = Depends(get_logger)):
    global g_ztk
    if g_ztk is None:
        g_ztk = ZTKStd(SConfig.ZTKSid, logger)
    return g_ztk
 async def get_data_list_search(name: str, page: int, sid: str,
                                logger: BoundLogger) -> List[TbkItemInfo]:
     ztk = ZTKStd(sid, logger=logger)
     args = SearchArgs(q=name, page=page)
     data_list = await ztk.search(args)
     return data_list