def immediately_sync_message(shop): time_format = "%Y-%m-%dT%H:%M:%S" start = datetime.datetime.now() - timedelta(minutes=30) end = datetime.datetime.now() + timedelta(minutes=5) timestamp = start.strftime(time_format) + ";" + end.strftime( time_format) ################## print(shop.platform) print(shop.site_id) print(shop.account) print(shop.owner) print(shop.id) shop.token = "AgAAAA**AQAAAA**aAAAAA**7HTjVw**nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6ABkoGoD5aHpAqdj6x9nY+seQ**94UCAA**AAMAAA**UGJaMLGzkw/V30Q7yrFVpkDxh9+F1v7X7taOlLW6WeEQCY/F6PhqPrjJfFLfw5rg93LNBvSQV4hO/cLtHS1K059mXzg61q4xHToNFk2uK+DdoFlCGbc1BD0TRyZ9zOSw4peeHJy/XUG2GwzkyPSrkBlU8X8e2IcZiyqCEILF0yl0ffDJy4Yz62JZVYCCX7HzvI/39N3ROGcUpCVbmxPE+QJI4a2Xst9ApBikHreVDntERITCRj8FhnnmAoDHGWziGN5GlNOQ40ETGX9GUX9yjK31haSpTpIsJRQBYhYeOYwo+F+LV5mFR55XDtuKD837jmKGZvpwll2pN4XhJfVbU7VFWbqyi2p4ccjxNEKXqmbJSSESvXmhiNK5J5EmAZVxh0BmXnNAHYCMJ1gZ7+sa4shnnzH12wcjMjK679iwXyYiK1YTrNmLNei4UeDFBfb2fzqm+eSDQIBK9g+HX/fZkTssU0O1m59wTeS+9GG6Bu7wTZyjU5cbCbjlQl6J4xhy4rs+efJLLAx/PfXmAODHgPF1Ai4rF/YYogFy+V9G0SiQJLQz31yxD3uJuDNyVoEB7/voPAvVutUvZcJzw2LAHIETfHG7GNMoHFA1fyLOF76YIZzsxBylxRY/x12gLlHFaKrtNAJRWpbKHO6usD0GMehDd9a/ALlSqHMPolKyaN6RMWEdov/Drq5PYTW+2OmO8GYyzrmCSk8s+OEv4LhLwkL4YBdYZyKoGo7Qf2FTqbfuYOKMblMi2MDACFSYKuvZ" shop.site_id = "0" ###################### handler = SyncEbayCustomer(shop, timestamp) try: logger.info(timestamp) for message_dict in handler.execute(): if not message_dict: continue for channel_id, message_ids in message_dict.items(): for i in range(0, len(message_ids), 10): sync_customer_detail(handler.shop, channel_id, message_ids=message_ids[i:i + 10]) except Exception, e: logger.warning(traceback.format_exc(e))
def sync_smt_customer_list(task_id, shop_id, timestamp): with sessionCM() as session: task = Task.find_by_id(session, task_id) shop = Shop.find_by_id(session, shop_id) handler = SyncSmtCustomer(shop, timestamp) try: handler.execute() task.status = 1 task.remark = timestamp except Exception, e: logger.warning(traceback.format_exc(e)) task.status = -1 finally:
def sync_evaluation_list(task_id, shop_id, timestamp): method_route = { "eBay": SyncEbayEvaluation, "AliExpress": SyncSmtEvaluation } with sessionCM() as session: task = Task.find_by_id(session, task_id) shop = Shop.find_by_id(session, shop_id) handler = method_route[shop.platform](shop) try: logger.info(timestamp) handler.execute() task.status = 1 task.remark = timestamp except Exception, e: logger.warning(traceback.format_exc(e)) task.status = -1 finally:
def sync_customer_list(task_id, shop_id, timestamp): method_route = { "eBay": SyncEbayCustomer, "Wish": SyncWishCustomer, } with sessionCM() as session: task = Task.find_by_id(session, task_id) shop = Shop.find_by_id(session, shop_id) handler = method_route[shop.platform](shop, timestamp) try: logger.info(timestamp) handler.execute() task.status = 1 task.remark = timestamp except Exception, e: logger.warning(traceback.format_exc(e)) task.status = -1 finally:
def upload_image(self, pic_url, pic_name): content = self.get_image_content(pic_url) if not content: return "" logger.info("已请求到图片%s, 并开始上传" % pic_url) self.need_signature = True path = "param2/1/aliexpress.open/api.uploadImage/%d" % self.config.get("app_key") url = "http://gw.api.alibaba.com/fileapi/" + path params = { "access_token": str(self.account), "fileName": pic_name } signature = api_signature_rule(self.config.get("secret_key"), path, params) params.update(_aop_signature=signature) url = "?".join([url, urlencode(params)]) res = requests.post(url, data=content, timeout=30) logger.info("图片%s已完成上传,获得到的请求结果是:" % pic_url) logger.info(res.text) res_dict = json.loads(res.text) if res_dict.get("error_code") == "401": logger.warning("F**K:上传图片又出现了401错误") if res_dict.get("status") == "NOCAPACITY": logger.warning("F**K:上传图片又出现了NO CAPACITY错误") if res_dict.get("status") == "EXCEPTION": logger.warning("EXCEPTION:上传图片出现了错误") return res_dict.get("photobankUrl", "")