Esempio n. 1
0
    def CancelFeedSubmissions(execute_command):
        params = ['Action=CancelFeedSubmissions'] + api_version + [
            'Timestamp=' + common_unit.get_time_stamp()
        ]
        # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id'])
        params += common_unit.make_access_param(execute_command)

        if 'submission_id_list' in execute_command:
            if execute_command['submission_id_list'] != '':
                id_list = execute_command['submission_id_list'].split(',')
                submission_id_list = []
                for i in id_list:
                    submission_id_list.append('FeedSubmissionIdList.Id.' +
                                              str(id_list.index(i) + 1) + '=' +
                                              i)
                params += submission_id_list

        if 'feed_type' in execute_command:
            if execute_command['feed_type'] != '':
                feed_list = execute_command['feed_type'].split(',')
                feed_type_list = []
                for i in feed_list:
                    feed_type_list.append('FeedTypeList.Type.' +
                                          str(feed_list.index(i) + 1) + '=' +
                                          i)
                params += feed_type_list

        if 'start_time' in execute_command:
            if execute_command['start_time'] != '':
                st = common_unit.conver_time(execute_command['start_time'])
                st = quote(st)
                params.append('SubmittedFromDate=' + st)

        if 'end_time' in execute_command:
            if execute_command['end_time'] != '':
                et = common_unit.conver_time(execute_command['end_time'])
                et = quote(et)
                params.append('SubmittedToDate=' + et)

        params = params + default_params
        params = sorted(params)
        params = '&'.join(params)
        sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params
        signature = quote(
            str(
                common_unit.cal_signature(sig_string,
                                          execute_command['secret_key'])))
        url = connect_url(params, signature)
        r = requests.post(url, headers=headers)
        result = common_unit.xmltojson(r.text)
        error_result = common_unit.catch_exception(result)  # 异常处理
        if error_result != '':
            result = error_result
        return result
Esempio n. 2
0
    def RequestReport(execute_command):
        if common_unit.test_access_param(execute_command) == 0:
            result = common_unit.read_xmlfile('test_file/requestReport.xml')
        else:
            params = ['Action=RequestReport'
                      ] + ['Timestamp=' + common_unit.get_time_stamp()]
            # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id'])
            access_params = common_unit.make_access_param(execute_command)
            market_place_id = access_params[-1].split('=')[1]
            access_params += ['MarketplaceIdList.Id.1=' + market_place_id]
            params = params + access_params  # 获取包含认证参数的字典
            if 'report_type' in execute_command:
                if execute_command['report_type'] != '':
                    params.append('ReportType=' +
                                  quote(execute_command['report_type']))

            if 'start_time' in execute_command:
                s = execute_command['start_time']
                if s != '':
                    st = common_unit.conver_time(s)
                    st = quote(st)
                    params.append('StartDate=' + st)

            if 'end_time' in execute_command:
                e = execute_command['end_time']
                if e != '':
                    et = common_unit.conver_time(e)
                    et = quote(et)
                    params.append('EndDate=' + et)

            params = params + default_params
            params = sorted(
                params)  # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序,拼接请求身,需要按首字母排序
            params = '&'.join(params)  # 对请求身进行分割
            sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params  # 连接签名字符串
            signature = quote(
                str(
                    common_unit.cal_signature(
                        sig_string,
                        execute_command['secret_key'])))  # 计算字符串的加密签名
            signature = signature.replace('/', '%2F')
            url = connect_url(params, signature)  # 拼接请求字符串
            # print(url)
            r = requests.post(url, headers=headers)  # 发起请求
            result = common_unit.xmltojson(r.text)
            # print(r.text)
            error_result = common_unit.catch_exception(result)  #异常处理
            if error_result != '':
                result = error_result
        return result
Esempio n. 3
0
    def ListFinancialEvents(execute_command):
        params = ['Action=ListFinancialEvents'] + api_version + [
            'Timestamp=' + common_unit.get_time_stamp()
        ]
        # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id'])
        params += common_unit.make_access_param(execute_command)  # 获取包含认证参数的字典

        if 'page' in execute_command:
            if execute_command['page'] != '':
                params.append('MaxResultsPerPage=' +
                              quote(execute_command['page']))  #返回结果页数

        if 'order_id' in execute_command:
            if execute_command['order_id'] != '':
                params.append('AmazonOrderId=' +
                              quote(execute_command['order_id']))  #订单编号

        if 'event_group_id' in execute_command:
            if execute_command['event_group_id'] != '':
                params.append('FinancialEventGroupId=' +
                              quote(execute_command['event_group_id']))  #事件组编号

        if 'start_time' in execute_command:
            if execute_command['start_time'] != '':
                st = common_unit.conver_time(execute_command['start_time'])
                st_timeArray = quote(st)
                params.append('PostedAfter=' + st_timeArray)  #开始时间

        if 'end_time' in execute_command:
            if execute_command['end_time'] != '':
                et = common_unit.conver_time(execute_command['end_time'])
                et_timeArray = quote(et)
                params.append('PostedBefore=' + et_timeArray)  #结束时间

        params = params + default_params
        params = sorted(params)  # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序,拼接请求身,需要按首字母排序
        params = '&'.join(params)  # 对请求身进行分割
        sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params  # 连接签名字符串
        signature = quote(
            str(
                common_unit.cal_signature(
                    sig_string, execute_command['secret_key'])))  # 计算字符串的加密签名
        url = connect_url(params, signature)  # 拼接请求字符串
        r = requests.post(url, headers=headers)  # 发起请求
        result = common_unit.xmltojson(r.text)
        error_result = common_unit.catch_exception(result)  # 异常处理
        if error_result != '':
            result = error_result
        return result
Esempio n. 4
0
 def ListOrders(execute_command):
     if common_unit.test_access_param(execute_command) != -1:
         result = common_unit.read_xmlfile('test_file/order_list.xml')
         result = eval(result)
         test_common.get_test_order_list(execute_command, result)
     else:
         params = ['Action=ListOrders'] + api_version + [
             'Timestamp=' + common_unit.get_time_stamp()
         ]
         # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id'])
         params += common_unit.make_access_param(execute_command)
         params[-1] = 'MarketplaceId.Id.1=' + params[-1].split('=')[1]
         if 'create_time' in execute_command:
             if execute_command['create_time'] != '':
                 ct = common_unit.conver_time(
                     execute_command['create_time'])
                 c_time = quote(ct)
                 params += ['CreatedAfter=' + c_time]
             else:
                 params += ['CreatedAfter=' + quote('1970-01-01T00:00:00')]
         if 'end_time' in execute_command:
             if execute_command['end_time'] != '':
                 # params += ['CreatedBefore=' + quote(execute_command['end_time'] + 'T00:00:00')]
                 et = common_unit.conver_time(execute_command['end_time'])
                 e_time = quote(et)
                 params += ['CreatedBefore=' + e_time]
             else:
                 delay = datetime.datetime.now() - datetime.timedelta(
                     days=1)
                 e_time = delay.strftime('%Y-%m-%dT%H:%M:%S')
                 params += ['CreatedBefore=' + quote(e_time)]
         params = params + default_params
         params = sorted(params)
         params = '&'.join(params)
         sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params  # 连接签名字符串
         signature = quote(
             str(
                 common_unit.cal_signature(
                     sig_string,
                     execute_command['secret_key'])))  # 计算字符串的加密签名
         url = connect_url(params, signature)
         r = requests.post(url, headers=headers)  # 发起请求
         result = common_unit.xmltojson(r.text)
         error_result = common_unit.catch_exception(result)  # 异常处理
         if error_result != '':
             result = error_result
     return result
Esempio n. 5
0
    def ListInventorySupply(execute_command):
        if common_unit.test_access_param(execute_command) == 0:
            # result = common_unit.read_xmlfile('test_file/inventory_list.xml')
            result = common_unit.xmltojson(str(inventory))
            result = test_interface.select_inventory_list(result)
        else:
            params = ['Action=ListInventorySupply'] + api_version + [
                'Timestamp=' + common_unit.get_time_stamp()
            ]
            # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id'])
            params += common_unit.make_access_param(
                execute_command)  # 获取包含认证参数的字典

            if 'sku' in execute_command:
                if execute_command['sku'] != '':
                    sku_list = execute_command['sku'].split(',')
                    sku_params_list = []
                    for i in sku_list:
                        sku_params_list.append('SellerSkus.member.' +
                                               str(sku_list.index(i) + 1) +
                                               '=' + i)
                    params += sku_params_list

            if 'start_time' in execute_command:
                if execute_command['start_time'] != '':
                    st = execute_command['start_time']
                    s_time = common_unit.conver_time(st)
                    params.append('QueryStartDateTime=' + quote(s_time))

            if 'response_group' in execute_command:
                if execute_command['response_group'] != '':
                    params.append('ResponseGroup=' +
                                  quote(execute_command['response_group']))

            params = params + default_params
            params = sorted(
                params)  # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序,拼接请求身,需要按首字母排序
            params = '&'.join(params)  # 对请求身进行分割
            params = params.replace('+', "%2B")
            params = params.replace(' ', "%20")
            sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params  # 连接签名字符串
            signature = quote(
                str(
                    common_unit.cal_signature(sig_string,
                                              execute_command['secret_key'])))
            signature = signature.replace('/', '%2F')
            # print(signature)
            # signature = signature.replace('=','%3D') # 计算字符串的加密签名
            url = connect_url(params, signature)  # 拼接请求字符串
            r = requests.post(url, headers=headers)  # 发起请求
            result = common_unit.xmltojson(r.text)
            error_result = common_unit.catch_exception(result)  # 异常处理
            if error_result != '':
                result = error_result
        return result
Esempio n. 6
0
    def ListAllFulfillmentOrders(execute_command):
        if common_unit.test_access_param(execute_command) == 0:
            # result = common_unit.xmltojson(listAllfulfillmentOrder)
            # result = common_unit.read_xmlfile('test_file/listAllfulfillmentorder.xml')

            if 'start_time' in execute_command:
                if execute_command['start_time'] != '':
                    start_time = execute_command['start_time']
                    start_date, time_stamp = common_unit.conver_date_time(
                        start_time)
                    # print(start_time,time_stamp)
                    result = common_unit.xmltojson(listAllfulfillmentOrder)
                    result = test_interface.listAllfulfillmentOrders_between_time(
                        start_date, result)

        else:
            params = ['Action=ListAllFulfillmentOrders'] + api_version + [
                'Timestamp=' + common_unit.get_time_stamp()
            ]
            # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id'])
            params += common_unit.make_access_param(execute_command)
            if 'start_time' in execute_command:
                if execute_command['start_time'] != '':
                    st = execute_command['start_time']
                    st = common_unit.conver_time(st)
                    params.append('QueryStartDateTime=' + quote(st))
            params = params + default_params
            params = sorted(params)
            params = '&'.join(params)
            sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params
            signature = quote(
                str(
                    common_unit.cal_signature(sig_string,
                                              execute_command['secret_key'])))
            url = connect_url(params, signature)
            r = requests.post(url, headers=headers)
            print(r.text)
            result = common_unit.xmltojson(r.text)
            error_result = common_unit.catch_exception(result)  # 异常处理
            if error_result != '':
                result = error_result
        return result
Esempio n. 7
0
    def UpdateFulfillmentOrder(execute_command):
        params = ['Action=UpdateFulfillmentOrder'] + api_version + [
            'Timestamp=' + common_unit.get_time_stamp()
        ]
        # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id'])
        params += common_unit.make_access_param(execute_command)

        if 'fulfillment_order_id' in execute_command:
            if execute_command['fulfillment_order_id'] != '':
                params.append('SellerFulfillmentOrderId=' +
                              quote(execute_command['fulfillment_order_id']))
        if 'fulfillment_action' in execute_command:
            if execute_command['fulfillment_action'] != '':
                params.append('FulfillmentAction=' +
                              quote(execute_command['fulfillment_action']))
        if 'display_order_id' in execute_command:
            if execute_command['display_order_id'] != '':
                params.append('DisplayableOrderId=' +
                              quote(execute_command['display_order_id']))
        if 'display_order_datetime' in execute_command:
            if execute_command['display_order_datetime'] != '':
                order_datetime = execute_command['display_order_datetime']
                order_datetime = common_unit.conver_time(order_datetime)
                params.append('DisplayableOrderDateTime=' +
                              quote(order_datetime))
        if 'display_order_comment' in execute_command:
            if execute_command['display_order_comment'] != '':
                params.append('DisplayableOrderComment=' +
                              quote(execute_command['display_order_comment']))
        if 'ship_speed_category' in execute_command:
            if execute_command['ship_speed_category'] != '':
                params.append('ShippingSpeedCategory=' +
                              quote(execute_command['ship_speed_category']))
        if 'address_name' in execute_command:
            if execute_command['address_name'] != '':
                params.append('DestinationAddress.Name=' +
                              quote(execute_command['address_name']))
        if 'address_line1' in execute_command:
            if execute_command['address_line1'] != '':
                params.append('DestinationAddress.Line1=' +
                              quote(execute_command['address_line1']))
        if 'address_line2' in execute_command:
            if execute_command['address_line2'] != '':
                params.append('DestinationAddress.Line2=' +
                              quote(execute_command['address_line2']))
        if 'address_line3' in execute_command:
            if execute_command['address_line3'] != '':
                params.append('DestinationAddress.Line2=' +
                              quote(execute_command['address_line3']))
        if 'district_or_country' in execute_command:
            if execute_command['district_or_country'] != '':
                params.append('DestinationAddress.DistrictOrCounty=' +
                              quote(execute_command['district_or_country']))
        if 'address_city' in execute_command:
            if execute_command['address_city'] != '':
                params.append('DestinationAddress.City=' +
                              execute_command['address_city'])
        if 'country_code' in execute_command:
            if execute_command['country_code'] != '':
                params.append('DestinationAddress.CountryCode=' +
                              quote(execute_command['country_code']))
        if 'state_or_province' in execute_command:
            if execute_command['state_or_province'] != '':
                params.append('DestinationAddress.StateOrProvinceCode=' +
                              quote(execute_command['state_province_code']))
        if 'post_code' in execute_command:
            if execute_command['post_code'] != '':
                params.append('DestinationAddress.PostalCode=' +
                              quote(execute_command['post_code']))
        if 'phone_number' in execute_command:
            if execute_command['phone_number'] != '':
                params.append('DestinationAddress.PhoneNumber=' +
                              quote(execute_command['phone_number']))
        if 'fulfillment_policy' in execute_command:
            if execute_command['fulfillment_policy'] != '':
                params.append('FulfillmentPolicy=' +
                              quote(execute_command['fulfillment_policy']))
        if 'notific_email_list' in execute_command:
            if execute_command['notific_email_list'] != '':
                email_list = execute_command['notific_email_list'].split(',')
                email_param_list = []
                for q in email_list:
                    email_param_list.append('NotificationEmailList.member.' +
                                            str(email_list.index(q) + 1) +
                                            '=' + q)
                params += email_param_list
        if 'sku' in execute_command:
            if execute_command['sku'] != '':
                sku_list = execute_command['sku'].split(',')
                sku_param_list = []
                for i in sku_list:
                    sku_param_list.append('Items.member.' +
                                          str(sku_list.index(i) + 1) + '=' + i)
                params += sku_param_list

        if 'order_item_id' in execute_command:
            if execute_command['order_item_id'] != '':
                sku_list = execute_command['order_item_id'].split(',')
                sku_param_list = []
                for i in sku_list:
                    sku_param_list.append('Items.member.' +
                                          str(sku_list.index(i) + 1) + '=' + i)
                params += sku_param_list

        if 'quantity' in execute_command:
            if execute_command['quantity'] != '':
                quantity_list = execute_command['quantity'].split(',')
                quantity_param_list = []
                for q in quantity_list:
                    quantity_param_list.append('Items.member.' +
                                               str(quantity_list.index(q) +
                                                   1) + '=' + q)
                params += quantity_param_list
        # params.append('Items.member.1.SellerSKU=' + quote(execute_command['sku']))
        # params.append('Items.member.1.SellerFulfillmentOrderItemId=' + quote(execute_command['order_item_id']))
        # params.append('Items.member.1.Quantity=' + quote(execute_command['quantity']))
        # params.append('Items.member.1.GiftMessage=' + quote(execute_command['gift_message']))
        # params.append('Items.member.1.DisplayableComment=' + quote(execute_command['dispaly_comment']))
        # params.append('Items.member.1.FulfillmentNetworkSKU=' + quote(execute_command['network_sku']))
        # params.append('Items.member.1.PerUnitDeclaredValue.CurrencyCode=' + quote(execute_command['puv_currency_code']))
        # params.append('Items.member.1.PerUnitDeclaredValue.Value=' + quote(execute_command['puv_value']))
        # params.append('Items.member.1.PerUnitPrice.CurrencyCode=' + quote(execute_command['pup_currency_code']))
        # params.append('Items.member.1.PerUnitPrice.Value=' + quote(execute_command['pup_value']))
        # params.append('Items.member.1.PerUnitTax.CurrencyCode=' + quote(execute_command['put_currency_code']))
        # params.append('Items.member.1.PerUnitTax.Value=' + quote(execute_command['put_value']))

        params = params + default_params
        params = sorted(params)
        params = '&'.join(params)
        params = params.replace('+', '%2B')
        params = params.replace('/', '%2F')
        print(params)
        sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params
        signature = quote(
            str(
                common_unit.cal_signature(sig_string,
                                          execute_command['secret_key'])))
        signature = signature.replace('+', '%2B').replace('/', '%2F')
        url = connect_url(params, signature)
        r = requests.post(url, headers=headers)
        result = common_unit.xmltojson(r.text)
        error_result = common_unit.catch_exception(result)
        if error_result != '':
            result = error_result
        return result
Esempio n. 8
0
    def GetReportRequestList(execute_command):
        if common_unit.test_access_param(execute_command) == 0:
            result = common_unit.read_xmlfile(
                'test_file/getReportRequestList.xml')
        else:
            params = ['Action=GetReportRequestList'] + api_version + [
                'Timestamp=' + common_unit.get_time_stamp()
            ]
            # user_access_dict = common_unit.get_amazon_keys(execute_command['store_id'])
            params += common_unit.make_access_param(
                execute_command)  # 获取包含认证参数的字典
            if 'report_request_id' in execute_command:
                if execute_command['report_request_id'] != '':
                    request_id_list = execute_command[
                        'report_request_id'].split(',')
                    request_list = []
                    for i in request_id_list:
                        request_list.append('ReportRequestIdList.Id.' +
                                            str(request_id_list.index(i) + 1) +
                                            '=' + i)
                    params += request_list

            if 'report_type' in execute_command:
                if execute_command['report_type'] != '':
                    report_list = execute_command['report_type'].split(',')
                    report_type_list = []
                    for i in report_list:
                        report_type_list.append('ReportTypeList.Type.' +
                                                str(report_list.index(i) + 1) +
                                                '=' + i)
                    params += report_type_list

            if 'process_status' in execute_command:
                if execute_command['process_status'] != '':
                    process_status_list = execute_command[
                        'process_status'].split(',')
                    process_list = []
                    for i in process_status_list:
                        process_list.append(
                            'ReportProcessingStatusList.Status.' +
                            str(process_status_list.index(i) + 1) + '=' + i)
                    params += process_list

            if 'max_count' in execute_command:
                if execute_command['max_count'] != '':
                    params.append('MaxCount=' +
                                  quote(execute_command['max_count']))

            if 'start_time' in execute_command:
                if execute_command['start_time'] != '':
                    st = common_unit.conver_time(execute_command['start_time'])
                    st = quote(st)
                    params.append('RequestedFromDate=' + st)  #开始时间

            if 'end_time' in execute_command:
                if execute_command['end_time'] != '':
                    et = common_unit.conver_time(execute_command['end_time'])
                    et = quote(et)
                    params.append('RequestedToDate=' + et)  #结束时间

            params = params + default_params
            params = sorted(
                params)  # 拼接公有请求参数,认证请求参数,和特征请求参数,并进行排序,拼接请求身,需要按首字母排序
            params = '&'.join(params)  # 对请求身进行分割
            sig_string = 'POST\n' + host_name + '\n' + port_point + '\n' + params  # 连接签名字符串
            signature = quote(
                str(
                    common_unit.cal_signature(
                        sig_string,
                        execute_command['secret_key'])))  # 计算字符串的加密签名
            url = connect_url(params, signature)  # 拼接请求字符串
            r = requests.post(url, headers=headers)  # 发起请求
            result = common_unit.xmltojson(r.text)
            # print(r.text)
            error_result = common_unit.catch_exception(result)  # 异常处理
            if error_result != '':
                result = error_result

        return result