示例#1
0
 def submitfeed(self, auth_info, data, feed_type):
     region = auth_info['ShopName'].split('/')[0].split('-')[-1]
     submitfeed = Feeds(auth_info['AWSAccessKeyId'], auth_info['SecretKey'], auth_info['SellerId'], region=region)
     marketplaceids = [auth_info['MarketplaceId']]
     submitfeed_rsp = submitfeed.submit_feed(data, feed_type, marketplaceids=marketplaceids)
     submitfeed_rsp_dict = submitfeed_rsp.parsed
     return submitfeed_rsp_dict
示例#2
0
 def submit_feed(auth_info, data, feed_type):
     submit_feed_public = Feeds(auth_info['AWSAccessKeyId'], auth_info['SecretKey'], auth_info['SellerId'], auth_info['ShopSite'])
     market_place_ids = [auth_info['MarketplaceId']]
     submit_feed_rsp = submit_feed_public.submit_feed(data, feed_type, marketplaceids=market_place_ids)
     submit_feed_rsp_dict = submit_feed_rsp.parsed
     print submit_feed_rsp_dict
     logging.debug('submit_feed_rsp_dict: %s' % str(submit_feed_rsp_dict))
     return submit_feed_rsp_dict
示例#3
0
 def get_deal_status(auth_info, feed_id):
     """
         获取提交所提交请求的处理状态,当为 '_DONE_' 时表示处理完成,此时方可提交申请获取处理结果信息
     """
     get_status_public = Feeds(auth_info['AWSAccessKeyId'], auth_info['SecretKey'], auth_info['SellerId'], auth_info['ShopSite'])
     get_status_rsp = get_status_public.get_feed_submission_list([feed_id])
     get_status_rsp_dict = get_status_rsp.parsed
     feed_processing_status = get_status_rsp_dict['FeedSubmissionInfo']['FeedProcessingStatus']['value']
     return feed_processing_status
    def get_deal_result(self, auth_info, data):
        """
         获取处理结果信息,设定总共等待31倍time_sleep时长检查请求是否处理完成(本例等待 31*10=310 秒)
        超过等待时长则设为处理超时
        """
        get_result_public = Feeds(auth_info['AWSAccessKeyId'],
                                  auth_info['SecretKey'],
                                  auth_info['SellerId'], auth_info['ShopSite'])
        feed_id = data['FeedSubmissionInfo']['FeedSubmissionId']['value']

        print '\n'
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        print 'result id is: %s, now wait for  10 seconds  then check deal status.' % feed_id
        logging.debug(
            'result id is: %s, now wait for  10 seconds  then check deal status.'
            % feed_id)

        time_sleep = 10
        count = 0
        while count < 5:
            time.sleep(time_sleep)
            time_sleep += time_sleep  # 每次等待时长翻倍(即10,20,40,80,160)
            count += 1
            try:
                feed_processing_status = self.get_deal_status(
                    auth_info, feed_id)
                if feed_processing_status == '_DONE_':
                    print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                    print 'now we can get the result'
                    logging.debug('now we can get the result')
                    feed_result = get_result_public.get_feed_submission_result(
                        feed_id)
                    print 'get result raw'
                    logging.debug('get result raw')
                    response = feed_result._response_dict
                    print 'get result dict'
                    logging.debug('get result dict: %s' % str(response))
                    print response
                    return response
                else:
                    print '\n'
                    print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                    print 'processing_status is:%s, we will wait for %s seconds ' % (
                        feed_processing_status, time_sleep)
                    logging.debug(
                        'processing_status is:%s, we will wait for %s seconds '
                        % (feed_processing_status, time_sleep))
            except Exception as e:
                print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                print 'error: %s' % e
                logging.error('error: %s' % e)
        else:  # 循环超过5次,即总等待时长超过 31*time_sleep,则计为超时
            print 'Get submit_feed reuslt timeout'
            logging.error('Get submit_feed reuslt timeout')
            return None
示例#5
0
 def submitfeed(self, auth_info, data, feed_type):
     region = auth_info['ShopName'].split('/')[0].split('-')[-1]
     submitfeed = Feeds(auth_info['AWSAccessKeyId'], auth_info['SecretKey'], auth_info['SellerId'], region=region)
     marketplaceids = [auth_info['MarketplaceId']]
     try:
         submitfeed_rsp = submitfeed.submit_feed(data, feed_type, marketplaceids=marketplaceids)
     except Exception as e:
         print e
         logger.error('traceback.format_exc():\n%s' % traceback.format_exc())
         logger.debug('we will submit feed again after 30 seconds')
         time.sleep(30)
         submitfeed_rsp = submitfeed.submit_feed(data, feed_type, marketplaceids=marketplaceids)
     submitfeed_rsp_dict = submitfeed_rsp.parsed
     return submitfeed_rsp_dict
 def __init__(self, db_connect, auth_info_update):
     self.db_conn = db_connect
     self.auth_info = auth_info_update
     self.submit_feed_public = Feeds(self.auth_info['AWSAccessKeyId'],
                                     self.auth_info['SecretKey'],
                                     self.auth_info['SellerId'],
                                     self.auth_info['ShopSite'],
                                     proxy_host=self.auth_info['IP'])
 def __init__(self, auth_info_feed, db_conncetion=connection):
     self.auth_info = auth_info_feed
     self.feed_public = Feeds(self.auth_info['AWSAccessKeyId'],
                              self.auth_info['SecretKey'],
                              self.auth_info['SellerId'],
                              region=self.auth_info['ShopSite'],
                              proxy_host=self.auth_info['IP'])
     self.product_public = Products(self.auth_info['AWSAccessKeyId'],
                                    self.auth_info['SecretKey'],
                                    self.auth_info['SellerId'],
                                    region=self.auth_info['ShopSite'],
                                    proxy_host=self.auth_info['IP'])
     self.db_conn = db_conncetion
示例#8
0
 def _get_mws(self,obj):
     mws_access_key, mws_secret_key = self.mws_access_key, self.mws_secret_key
     mws_merchant_id, mws_marketplace_id = self.mws_merchant_id, self.mws_marketplace_id
     region, domain = self.region, self.domain
     if obj == 'Sellers':
         return Sellers(mws_access_key, mws_secret_key, mws_merchant_id, region=region, domain=domain)
     elif obj == 'Reports':
         return Reports(mws_access_key, mws_secret_key, mws_merchant_id, region=region, domain=domain)
     elif obj == 'Products':
         return Products(mws_access_key, mws_secret_key, mws_merchant_id, region=region, domain=domain)
     elif obj == 'Feeds':
         return Feeds(mws_access_key, mws_secret_key, mws_merchant_id, region=region, domain=domain)
     elif obj == 'Orders':
         return Orders(mws_access_key, mws_secret_key, mws_merchant_id, region=region, domain=domain,version='2013-09-01')
示例#9
0
 def getsubmitfeedresult(self, auth_info, data):
     '''
     _POST_PRODUCT_DATA_:
         {
             'Header': {
                 'MerchantIdentifier': {
                     'value': 'A3E57KPT99E29C'
                 },
                 'DocumentVersion': {'value': '1.02'},
                 'value': '\n\t\t'
             },
             'Message': {
                 'ProcessingReport': {
                     'DocumentTransactionID': {'value': '57844017533'},
                     'ProcessingSummary': {
                         'MessagesProcessed': {'value': '4'},
                         'MessagesWithWarning': {'value': '0'},
                         'MessagesSuccessful': {'value': '4'},
                         'value': '\n\t\t\t\t',
                         'MessagesWithError': {'value': '0'}
                     },
                     'value': '\n\t\t\t',
                     'StatusCode': {'value': 'Complete'}
                 },
                 'value': '\n\t\t',
                 'MessageID': {'value': '1'}
             },
             'noNamespaceSchemaLocation': {
                 'namespace': 'http://www.w3.org/2001/XMLSchema-instance',
                 'value': 'amzn-envelope.xsd'
             },
             'MessageType': {'value': 'ProcessingReport'},
             'value': '\n\t'
         }
     '''
     time.sleep(60)
     region = auth_info['ShopName'].split('/')[0].split('-')[-1]
     submitfeed = Feeds(auth_info['AWSAccessKeyId'], auth_info['SecretKey'], auth_info['SellerId'], region=region)
     feedid = data['FeedSubmissionInfo']['FeedSubmissionId']['value']
     time_sleep = 10
     count = 0
     while True:
         time.sleep(time_sleep)
         time_sleep += time_sleep
         count += 1
         try:
             feedresult = submitfeed.get_feed_submission_result(feedid)
             response = feedresult._response_dict
             if response.get('Message') and \
                     response.get('Message').get('ProcessingReport') and \
                     response.get('Message').get('ProcessingReport').get('StatusCode') and \
                     response.get('Message').get('ProcessingReport').get('StatusCode').get('value'):
                 logger.debug('Get submitfeed result: %s' % response)
                 return response
             # else:
             #     logger.debug('Have got submitfeed result but not complete: %s' % response)
         except Exception as e:
             print 'error: %s' % e
             logger.error('error: %s' % e)
         if count < 7:
             continue
         else:
             # return {'error': 'Get submitfeed reuslt timeout', 'code': 408}
             return {}