Ejemplo n.º 1
0
 def get_token(self, code):
     logger.info("AliSDK正在执行获取token的操作")
     try_times = 3
     while try_times > 0:
         res = None
         try:
             url = "https://gw.api.alibaba.com/openapi/param2/1/system.oauth2/getToken/%s" % self.config.get(
                 "app_key")
             logger.info(u"请求链接为:%s" % url)
             params = dict(grant_type="authorization_code",
                           need_refresh_token=True,
                           client_id=self.config.get("app_key"),
                           client_secret=self.config.get("secret_key"),
                           redirect_uri=self.config.get("redirect_uri"),
                           code=code)
             logger.info(u'请求参数:%s' % params)
             res = requests.post(url, params, timeout=20)
             logger.info(u'获取到的数据结果为%s' % res.text)
             logger.info("AliSDK请求执行完毕")
             return json.loads(res.text)
         except Exception, e:
             try_times -= 1
             if try_times <= 0:
                 logger.error({
                     "response": res.text if res else "授权请求3次均超时",
                     "message": traceback.format_exc(e)
                 })
Ejemplo n.º 2
0
 def get_token(self, code):
     logger.info("WishSDK正在执行获取token的操作")
     try_times = 3
     while try_times > 0:
         res = None
         try:
             url = "https://%s/api/v2/oauth/access_token" % self.domain
             logger.info(u"请求链接为:%s" % url)
             params = dict(grant_type="authorization_code",
                           client_id=self.config.get("client_id"),
                           client_secret=self.config.get("client_secret"),
                           redirect_uri=self.config.get("redirect_uri"),
                           code=code)
             logger.info(u'请求参数:%s' % params)
             res = requests.post(url, params, timeout=20)
             logger.info(u'获取到的数据结果为%s' % res.text)
             logger.info("WishSDK请求执行完毕")
             return res.json()
         except Exception, e:
             try_times -= 1
             if try_times <= 0:
                 logger.error({
                     "response": res.text if res else "授权请求3次均超时",
                     "message": traceback.format_exc(e)
                 })
Ejemplo n.º 3
0
    def update_channel_flag(self):
        """
        更新 channel 的标签

        参数:channel_id --> channel 的本地Id
             rank --> 标志 取值 rank0,rank1,rank2,rank3,rank4,rank5
                                (白,红,橙,绿,蓝,紫)
        :return:
        """
        channel_id = self.params.get("channel_id", "")
        rank = self.params.get("rank", "")

        with sessionCM() as session:
            channel = Channel.find_by_id(session, channel_id)

        if not channel:
            return {"status": 0, "data": "\"channel_id\"不存在!"}
        if rank not in ["rank0", "rank1", "rank2", "rank3", "rank4", "rank5"]:
            return {"status": 0, "data": "\"rank\"参数的值不在合法值列表中"}

        try:
            with sessionCM() as session:
                Channel.update(session, channel, {"flag": rank})
            return {
                "status": 1,
                "data": "为channel %s 打上了 %s 标签!" % (str(channel_id), str(rank))
            }
        except Exception, e:
            logger.error(traceback.format_exc(e))
            return {"status": 0, "data": "打标签失败"}
Ejemplo n.º 4
0
    def update_channel_state(self):
        """
        更新 channel 的处理状态 (已处理、未处理)

        参数:channel_id --> channel 的本地Id
            state --> 状态 0表示未处理、 1表示已处理
        :return:
        """
        channel_id = self.params.get("channel_id", "")
        state = self.params.get("state", "")

        with sessionCM() as session:
            channel = Channel.find_by_id(session, channel_id)

        if not channel:
            return {"status": 0, "data": "\"channel id\"不存在!"}

        if state not in ["1", "0"]:
            return {"status": 0, "data": "\"state\"值只能是字符串0或1!"}

        try:
            with sessionCM() as session:
                Channel.update(session, channel, {"deal_stat", int(state)})
            return {"status": 1, "data": "状态更新成功!"}
        except Exception, e:
            logger.error(traceback.format_exc(e))
            return {"status": 0, "data": "状态更新失败!"}
Ejemplo n.º 5
0
    def get(self, *args, **kwargs):
        logger_dict = {
            "args": args,
            "kwargs": kwargs,
            "params": self.params,
            "method": "GET"
        }
        print logger_dict
        method_route = {
            "channel": self.list_channel,
            "message": self.list_message,
            "channel/search": self.search_channel,
        }

        try:
            shop = self.get_shop()
            if not shop:
                self.write({
                    "status": 0,
                    "message": "错误的店铺ID、ChannelID、EvaluationID!"
                })
                return

            control = self.control_route[shop.platform](shop, **self.params)
            action = args[0]
            result = method_route[action](control)
            self.write(result)

            # if action == "channel":
            #     self.render("index.html", **result)
            # else:
            #     self.write(result)
        except Exception, e:
            logger.error(traceback.format_exc(e))
            self.write({"status": 0, "data": traceback.format_exc(e)})
Ejemplo n.º 6
0
def sync_smt_customer_detail(handler, channel_id, msg_source, **kwargs):
    try:
        print (u"AliExpress平台编号为%s的客服通道开始同步..." % str(channel_id))
        handler.sync_message_detail(channel_id, msg_source, **kwargs)
        logger.info(u"AliExpress平台编号为%s的客服通道同步成功" % str(channel_id))
    except Exception, e:
        logger.error(traceback.format_exc(e))
        logger.info(u"AliExpress平台编号为%s的客服通道同步失败,失败原因:%s" % (
            str(channel_id), traceback.format_exc(e)))
Ejemplo n.º 7
0
def sync_customer_detail(shop, channel_id, **kwargs):
    try:
        method_route = {
            "eBay": SyncEbayCustomer,
            "Wish": SyncWishCustomer,
        }
        handler = method_route[shop.platform](shop)
        handler.sync_message_detail(channel_id, **kwargs)
        logger.info(u"%s平台编号为%s的客服消息通道同步成功,IDs=%s" % (
            shop.platform, str(channel_id), str(kwargs["message_ids"])))
    except Exception, e:
        logger.error(traceback.format_exc(e))
        logger.info(u"%s平台编号为%s的客服消息通道同步失败,IDs=%s,失败原因:%s" % (
            shop.platform, str(channel_id), str(kwargs["message_ids"]), traceback.format_exc(e)))
Ejemplo n.º 8
0
def main():
    try:
        options.parse_command_line()
        port = options.options.port
        settings.configure('PORT', port)

        app = tornado.web.Application(handlers=handlers,
                                      session=session_settings,
                                      **SETTINGS)
        server = tornado.httpserver.HTTPServer(app)
        server.listen(settings.port)
        ioloop.IOLoop().instance().start()

    except Exception, e:
        print traceback.format_exc(e)
        logger.error(traceback.format_exc(e))
Ejemplo n.º 9
0
 def create(cls, platform, site, step, name=None):
     with sessionCM() as session:
         try:
             shop = session.query(cls).filter(
                 SA.and_(cls.platform == platform, cls.site == site)).one()
             return shop
         except NoResultFound:
             shop = cls()
             shop.name = name if name else cls.generate_shop_name(
                 platform, site)
             shop.platform = platform
             shop.site = site
             shop.step = step
             session.add(shop)
             session.commit()
             return shop
         except Exception, e:
             logger.error(e)
             return None
Ejemplo n.º 10
0
    def update_channel_read(self):
        """
        更新通道为已读状态

        参数 channel_id --> channel 的本地ID
            msgSource --> 消息类型 可选参数(message_center/order_msg)
        :return:
        """
        channel_id = self.params.get("channel_id", "")

        with sessionCM() as session:
            channel = Channel.find_by_id(session, channel_id)

        if not channel:
            return {"status": 0, "data": "\"channel_id\"不存在!"}

        try:
            with sessionCM() as session:
                Channel.update(session, channel, {"read_stat", 1})
            return {"status": 1, "data": "状态更新成功!"}
        except Exception, e:
            logger.error(traceback.format_exc(e))
            return {"status": 0, "data": "状态更新失败!"}