class ProductSchema(xm.Schema): ignore_missing = True class RankSchema(xm.Schema): category = xm.String('./ProductCategoryId') rank = xm.Int('./Rank') sku = xm.String('./Identifiers/MarketplaceASIN/ASIN') brand = xm.First(('.//Brand', './/Manufacturer', './/Label', './/Publisher', './/Studio')) model = xm.First(('.//Model', './/PartNumber')) price = xm.Float('.//ListPrice/Amount') NumberOfItems = xm.Int('.//NumberOfItems') PackageQuantity = xm.Int('.//PackageQuantity') image_url = xm.String('.//SmallImage/URL') title = xm.String('.//Title') ranks = xm.Nested('.//SalesRank', RankSchema(), many=True) features = xm.String('.//Feature', many=True) def post_load(self, data): if 'features' in data: data.features = '\n'.join(data.pop('features')) for ranking in data.pop('ranks', []): if not ranking['category'].isdigit(): data['category'] = ranking.category data['rank'] = ranking.rank break return data
class OrderSchema(xm.Schema): ignore_missing = True order_number = xm.String('.//AmazonOrderId', required=True) seller_order_id = xm.String('.//SellerOrderId') date = xm.String('.//PurchaseDate') status = xm.String('.//OrderStatus') prime = xm.Boolean('.//IsPrime') fulfillment_channel = xm.String('.//FulfillmentChannel') business = xm.Boolean('.//IsBusinessOrder') replacement = xm.Boolean('.//IsReplacementOrder') class CustomerSchema(xm.Schema): ignore_missing = True class AddressSchema(xm.Schema): ignore_missing = True city = xm.String('.//City') postal_code = xm.String('.//PostalCode') state = xm.String('.//StateOrRegion') country = xm.String('.//CountryCode') lines = xm.String( './/*[starts-with(name(), "AddressLine")]', many=True) name = xm.String('.//BuyerName') email = xm.String('.//BuyerEmail') address = xm.Field('.//ShippingAddress', AddressSchema())
class SupplySchema(xm.Schema): ignore_missing = True sku = xm.String('.//ASIN') fnsku = xm.String('.//FNSKU') msku = xm.String('.//SellerSKU') fulfillable = xm.Int('.//InStockSupplyQuantity') condition = xm.String('.//Condition')
class RetroChargeEvent(xm.Schema): ignore_missing = True type = xm.String('.//RetrochargeEventType') amazon_order_id = xm.String('.//AmazonOrderId') posted_date = xm.String('.//PostedDate') base_tax = xm.Float('.//BaseTax/Amount') shipping_tax = xm.Float('.//ShippingTax/Amount') marketplace = xm.String('.//MarketplaceName')
class AddressSchema(xm.Schema): ignore_missing = True city = xm.String('.//City') postal_code = xm.String('.//PostalCode') state = xm.String('.//StateOrRegion') country = xm.String('.//CountryCode') lines = xm.String( './/*[starts-with(name(), "AddressLine")]', many=True)
class AdjustmentItem(xm.Schema): ignore_missing = True quantity = xm.Int('.//Quantity') per_unit_amount = xm.Float('.//PerUnitAmount/Amount') total_amount = xm.Float('.//TotalAmount/Amount') msku = xm.String('.//SellerSKU') fnsku = xm.String('.//FnSKU') sku = xm.String('.//ASIN') description = xm.String('.//ProductDescription')
class OrderItemSchema(xm.Schema): ignore_missing = True sku = xm.String('.//ASIN', required=True) msku = xm.String('.//SellerSKU') order_item_id = xm.String('.//OrderItemId') title = xm.String('.//Title') qty_ordered = xm.Int('.//QuantityOrdered') qty_shipped = xm.Int('.//QuantityShipped') price = xm.Float('.//ItemPrice/Amount') currency_code = xm.String('.//ItemPrice/CurrencyCode') shipping_price = xm.Float('.//ShippingPrice/Amount')
class ProductSchema(xm.Schema): ignore_missing = True sku = xm.String('.//ASIN', required=True) detail_url = xm.Field( 'ASIN', cast=lambda tag: f'http://www.amazon.com/dp/{tag.text}') rank = xm.Int('SalesRank') category = xm.String('.//ProductGroup') image_url = xm.String('.//LargeImage/URL') brand = xm.First(('.//Brand', './/Manufacturer', './/Label', './/Publisher', './/Studio')) model = xm.First(('.//Model', './/MPN', './/PartNumber')) NumberOfItems = xm.Int('.//NumberOfItems') PackageQuantity = xm.Int('.//PackageQuantity') title = xm.String('.//Title') upc = xm.String('.//UPC') merchant = xm.String('.//Merchant/Name') prime = xm.Boolean('.//IsEligibleForPrime') features = xm.String('.//Feature', many=True) description = xm.String('.//EditorialReview/Content') price = xm.Field('.//OfferListing/Price/Amount', cast=lambda tag: int(tag.text) / 100) def post_load(self, data): if 'features' in data: data.features = '\n'.join(data.features) return data
class PackageSchema(xm.Schema): ignore_missing = True class Dimensions(xm.Schema): units = xm.String('.//Unit') height = xm.Float('.//Height') length = xm.Float('.//Length') width = xm.Float('.//Width') weight = xm.Float('.//Weight/Value') tracking_number = xm.String('.//TrackingId') carrier = xm.String('.//CarrierName') status = xm.String('.//PackageStatus') dimensions = xm.Field('.//Dimensions', Dimensions())
class ShipmentSchema(xm.Schema): class PrepDetailsSchema(xm.Schema): instruction = xm.String('.//PrepInstruction') owner = xm.String('.//PrepOwner') order_number = xm.String('.//ShipmentId', required=True) msku = xm.String('.//SellerSKU') fnsku = xm.String('.//FulfillmentNetworkSKU') quantity = xm.Int('.//QuantityShipped') received = xm.Int('.//QuantityReceived') case_quantity = xm.Int('.//QuantityInCase') prep_details = xm.Field('.//PrepDetails', PrepDetailsSchema(), many=True)
class ResponseSchema(MWSResponseSchema): """Response schema for ListInboundShipments.""" class ShipmentSchema(xm.Schema): ignore_missing = True class ContentsFeeSchema(xm.Schema): units = xm.Int('.//TotalUnits') per_unit = xm.Float('.//FeePerUnit/Amount') total = xm.Float('.//TotalFee/Amount') order_number = xm.String('.//ShipmentId', required=True) name = xm.String('.//ShipmentName') fulfillment_cented_id = xm.String( './/DestinationFulfillmentCenterId') label_prep_type = xm.String('.//LabelPrepType') status = xm.String('.//ShipmentStatus') cases_required = xm.Boolean('.//AreCasesRequired') need_by_date = xm.String('.//ConfirmedNeedByDate') box_contents_source = xm.String('.//BoxContentsSource') box_contents_fee = xm.Field('.//EstimatedBoxContentsFee', ContentsFeeSchema()) items = xm.Field('.//member', ShipmentSchema(), many=True, default=list) next_token = xm.String('.//NextToken', default=None)
class CustomerSchema(xm.Schema): ignore_missing = True class AddressSchema(xm.Schema): ignore_missing = True city = xm.String('.//City') postal_code = xm.String('.//PostalCode') state = xm.String('.//StateOrRegion') country = xm.String('.//CountryCode') lines = xm.String( './/*[starts-with(name(), "AddressLine")]', many=True) name = xm.String('.//BuyerName') email = xm.String('.//BuyerEmail') address = xm.Field('.//ShippingAddress', AddressSchema())
class ShipmentItem(xm.Schema): ignore_missing = True msku = xm.String('.//SellerSKU') order_item_id = xm.String('.//OrderItemId') order_adj_id = xm.String('.//OrderAdjustmentItemId') qty_shipped = xm.Int('.//QuantityShipped') charges = xm.Nested('.//ItemChargeList', ComponentList()) taxes = xm.Nested('.//TaxesWithheldList', ComponentList()) charge_adjustments = xm.Nested('.//ItemChargeAdjustmentList', ComponentList()) fees = xm.Nested('.//ItemFeeList', ComponentList()) fee_adjustments = xm.Nested('.//ItemFeeAdjustmentList', ComponentList()) promotions = xm.Nested('.//PromotionList/Promotion', Promotion()) promo_adjustments = xm.Nested( './/PromotionAdjustmentList/Promotion', Promotion())
class AdjustmentEvent(xm.Schema): ignore_missing = True class AdjustmentItem(xm.Schema): ignore_missing = True quantity = xm.Int('.//Quantity') per_unit_amount = xm.Float('.//PerUnitAmount/Amount') total_amount = xm.Float('.//TotalAmount/Amount') msku = xm.String('.//SellerSKU') fnsku = xm.String('.//FnSKU') sku = xm.String('.//ASIN') description = xm.String('.//ProductDescription') type = xm.String('.//AdjustmentType') amount = xm.Float('.//AdjustmentAmount/Amount') posted_date = xm.String('.//PostedDate') items = xm.List('.//AdjustmentItemList/AdjustmentItem', AdjustmentItem())
class ShipmentEvent(xm.Schema): ignore_missing = True class ShipmentItem(xm.Schema): ignore_missing = True msku = xm.String('.//SellerSKU') order_item_id = xm.String('.//OrderItemId') order_adj_id = xm.String('.//OrderAdjustmentItemId') qty_shipped = xm.Int('.//QuantityShipped') charges = xm.Nested('.//ItemChargeList', ComponentList()) taxes = xm.Nested('.//TaxesWithheldList', ComponentList()) charge_adjustments = xm.Nested('.//ItemChargeAdjustmentList', ComponentList()) fees = xm.Nested('.//ItemFeeList', ComponentList()) fee_adjustments = xm.Nested('.//ItemFeeAdjustmentList', ComponentList()) promotions = xm.Nested('.//PromotionList/Promotion', Promotion()) promo_adjustments = xm.Nested( './/PromotionAdjustmentList/Promotion', Promotion()) amazon_order_id = xm.String('.//AmazonOrderId') seller_order_id = xm.String('.//SellerOrderId') marketplace = xm.String('.//MarketplaceName') posted_date = xm.String('.//PostedDate') charges = xm.Nested('.//OrderChargeList', ComponentList()) charge_adjustments = xm.Nested('.//OrderChargeAdjustmentList', ComponentList()) shipment_fees = xm.Nested('.//ShipmentFeeList', ComponentList()) shipment_adjustments = xm.Nested('.//ShipmentFeeAdjustmentList', ComponentList()) fees = xm.Nested('.//OrderFeeList', ComponentList()) fee_adjustments = xm.Nested('.//OrderFeeAdjustmentList', ComponentList()) direct_payments = xm.Nested('.//DirectPaymentList', ComponentList()) items = xm.List('.//ShipmentItemList/ShipmentItem', ShipmentItem()) item_adjustments = xm.List( './/ShipmentItemAdjustments/ShipmentItem', ShipmentItem())
class MWSResponseSchema(xm.Schema): """Base schema for MWS responses.""" ignore_missing = True class Error(xm.Schema): """Schema for MWS errors.""" type = xm.Field('.//Type') code = xm.Field('.//Code') message = xm.Field('.//Message') request_id = xm.String('//RequestId') errors = xm.Field('//Error', Error(), default=list, many=True)
class EventGroupSchema(xm.Schema): ignore_missing = True group_id = xm.String('.//FinancialEventGroupId', required=True) group_status = xm.String('.//FinancialEventGroupStatus') fund_transfer_status = xm.String('.//FundTransferStatus') original_total = xm.Float('.//OriginalTotal/Amount') converted_total = xm.Float('.//ConvertedTotal/Amount') fund_transfer_date = xm.String('.//FundTransferDate') trace_id = xm.String('.//TraceId') account_tail = xm.String('.//AccountTail') beginning_balance = xm.Float('.//BeginningBalance/Amount') start_date = xm.String('.//FinancialEventGroupStartDate') end_date = xm.String('.//FinancialEventGroupEndDate')
class ResponseSchema(MWSResponseSchema): """Response schema for ListInventorySupply.""" class SupplySchema(xm.Schema): ignore_missing = True sku = xm.String('.//ASIN') fnsku = xm.String('.//FNSKU') msku = xm.String('.//SellerSKU') fulfillable = xm.Int('.//InStockSupplyQuantity') condition = xm.String('.//Condition') items = xm.Field('.//member', SupplySchema(), many=True, default=list) next_token = xm.String('.//NextToken', default=None)
class ServiceFeeEvent(xm.Schema): ignore_missing = True amazon_order_id = xm.String('.//AmazonOrderId') reason = xm.String('.//FeeReason') fees = xm.Nested('.//FeeList', ComponentList()) msku = xm.String('.//SellerSKU') fnsku = xm.String('.//FnSKU') description = xm.String('.//FeeDescription') sku = xm.String('.//ASIN')
class ResponseSchema(MWSResponseSchema): class OrderItemSchema(xm.Schema): ignore_missing = True sku = xm.String('.//ASIN', required=True) msku = xm.String('.//SellerSKU') order_item_id = xm.String('.//OrderItemId') title = xm.String('.//Title') qty_ordered = xm.Int('.//QuantityOrdered') qty_shipped = xm.Int('.//QuantityShipped') price = xm.Float('.//ItemPrice/Amount') currency_code = xm.String('.//ItemPrice/CurrencyCode') shipping_price = xm.Float('.//ShippingPrice/Amount') items = xm.Field('.//OrderItem', OrderItemSchema(), many=True, default=list) next_token = xm.String('.//NextToken', default=None)
class ShipmentSchema(xm.Schema): ignore_missing = True class ContentsFeeSchema(xm.Schema): units = xm.Int('.//TotalUnits') per_unit = xm.Float('.//FeePerUnit/Amount') total = xm.Float('.//TotalFee/Amount') order_number = xm.String('.//ShipmentId', required=True) name = xm.String('.//ShipmentName') fulfillment_cented_id = xm.String( './/DestinationFulfillmentCenterId') label_prep_type = xm.String('.//LabelPrepType') status = xm.String('.//ShipmentStatus') cases_required = xm.Boolean('.//AreCasesRequired') need_by_date = xm.String('.//ConfirmedNeedByDate') box_contents_source = xm.String('.//BoxContentsSource') box_contents_fee = xm.Field('.//EstimatedBoxContentsFee', ContentsFeeSchema())
class ResponseSchema(MWSResponseSchema): class EventGroupSchema(xm.Schema): ignore_missing = True group_id = xm.String('.//FinancialEventGroupId', required=True) group_status = xm.String('.//FinancialEventGroupStatus') fund_transfer_status = xm.String('.//FundTransferStatus') original_total = xm.Float('.//OriginalTotal/Amount') converted_total = xm.Float('.//ConvertedTotal/Amount') fund_transfer_date = xm.String('.//FundTransferDate') trace_id = xm.String('.//TraceId') account_tail = xm.String('.//AccountTail') beginning_balance = xm.Float('.//BeginningBalance/Amount') start_date = xm.String('.//FinancialEventGroupStartDate') end_date = xm.String('.//FinancialEventGroupEndDate') groups = xm.Field('.//FinancialEventGroup', EventGroupSchema(), many=True, default=list) next_token = xm.String('.//NextToken', default=None)
class ResponseSchema(MWSResponseSchema): class ShipmentSchema(xm.Schema): class PrepDetailsSchema(xm.Schema): instruction = xm.String('.//PrepInstruction') owner = xm.String('.//PrepOwner') order_number = xm.String('.//ShipmentId', required=True) msku = xm.String('.//SellerSKU') fnsku = xm.String('.//FulfillmentNetworkSKU') quantity = xm.Int('.//QuantityShipped') received = xm.Int('.//QuantityReceived') case_quantity = xm.Int('.//QuantityInCase') prep_details = xm.Field('.//PrepDetails', PrepDetailsSchema(), many=True) items = xm.Field('.//member', ShipmentSchema(), many=True, default=list) next_token = xm.String('.//NextToken', default=None)
class ResponseSchema(MWSResponseSchema): class PackageSchema(xm.Schema): ignore_missing = True class Dimensions(xm.Schema): units = xm.String('.//Unit') height = xm.Float('.//Height') length = xm.Float('.//Length') width = xm.Float('.//Width') weight = xm.Float('.//Weight/Value') tracking_number = xm.String('.//TrackingId') carrier = xm.String('.//CarrierName') status = xm.String('.//PackageStatus') dimensions = xm.Field('.//Dimensions', Dimensions()) shipping = xm.Float('.//PartneredEstimate/Amount/Value') transport_status = xm.String('.//TransportStatus', required=True) packages = xm.Field('//member', PackageSchema(), many=True, default=list)
class PrepDetailsSchema(xm.Schema): instruction = xm.String('.//PrepInstruction') owner = xm.String('.//PrepOwner')
class ResponseSchema(MWSResponseSchema): status = xm.String('.//Status')
class RankSchema(xm.Schema): category = xm.String('./ProductCategoryId') rank = xm.Int('./Rank')
class ResponseSchema(MWSResponseSchema): class ShipmentEvent(xm.Schema): ignore_missing = True class ShipmentItem(xm.Schema): ignore_missing = True msku = xm.String('.//SellerSKU') order_item_id = xm.String('.//OrderItemId') order_adj_id = xm.String('.//OrderAdjustmentItemId') qty_shipped = xm.Int('.//QuantityShipped') charges = xm.Nested('.//ItemChargeList', ComponentList()) taxes = xm.Nested('.//TaxesWithheldList', ComponentList()) charge_adjustments = xm.Nested('.//ItemChargeAdjustmentList', ComponentList()) fees = xm.Nested('.//ItemFeeList', ComponentList()) fee_adjustments = xm.Nested('.//ItemFeeAdjustmentList', ComponentList()) promotions = xm.Nested('.//PromotionList/Promotion', Promotion()) promo_adjustments = xm.Nested( './/PromotionAdjustmentList/Promotion', Promotion()) amazon_order_id = xm.String('.//AmazonOrderId') seller_order_id = xm.String('.//SellerOrderId') marketplace = xm.String('.//MarketplaceName') posted_date = xm.String('.//PostedDate') charges = xm.Nested('.//OrderChargeList', ComponentList()) charge_adjustments = xm.Nested('.//OrderChargeAdjustmentList', ComponentList()) shipment_fees = xm.Nested('.//ShipmentFeeList', ComponentList()) shipment_adjustments = xm.Nested('.//ShipmentFeeAdjustmentList', ComponentList()) fees = xm.Nested('.//OrderFeeList', ComponentList()) fee_adjustments = xm.Nested('.//OrderFeeAdjustmentList', ComponentList()) direct_payments = xm.Nested('.//DirectPaymentList', ComponentList()) items = xm.List('.//ShipmentItemList/ShipmentItem', ShipmentItem()) item_adjustments = xm.List( './/ShipmentItemAdjustments/ShipmentItem', ShipmentItem()) class RetroChargeEvent(xm.Schema): ignore_missing = True type = xm.String('.//RetrochargeEventType') amazon_order_id = xm.String('.//AmazonOrderId') posted_date = xm.String('.//PostedDate') base_tax = xm.Float('.//BaseTax/Amount') shipping_tax = xm.Float('.//ShippingTax/Amount') marketplace = xm.String('.//MarketplaceName') class ServiceFeeEvent(xm.Schema): ignore_missing = True amazon_order_id = xm.String('.//AmazonOrderId') reason = xm.String('.//FeeReason') fees = xm.Nested('.//FeeList', ComponentList()) msku = xm.String('.//SellerSKU') fnsku = xm.String('.//FnSKU') description = xm.String('.//FeeDescription') sku = xm.String('.//ASIN') class AdjustmentEvent(xm.Schema): ignore_missing = True class AdjustmentItem(xm.Schema): ignore_missing = True quantity = xm.Int('.//Quantity') per_unit_amount = xm.Float('.//PerUnitAmount/Amount') total_amount = xm.Float('.//TotalAmount/Amount') msku = xm.String('.//SellerSKU') fnsku = xm.String('.//FnSKU') sku = xm.String('.//ASIN') description = xm.String('.//ProductDescription') type = xm.String('.//AdjustmentType') amount = xm.Float('.//AdjustmentAmount/Amount') posted_date = xm.String('.//PostedDate') items = xm.List('.//AdjustmentItemList/AdjustmentItem', AdjustmentItem()) shipment_events = xm.List('.//ShipmentEventList/ShipmentEvent', ShipmentEvent()) refund_events = xm.List('.//RefundEventList/ShipmentEvent', ShipmentEvent()) guarantee_events = xm.List('.//GuaranteeClaimEventList/ShipmentEvent', ShipmentEvent()) chargeback_events = xm.List('.//ChargebackEventList/ShipmentEvent', ShipmentEvent()) retrocharge_events = xm.List( './/RetrochargeEventList/RetrochargeEvent', RetroChargeEvent()) service_fee_events = xm.List('.//ServiceFeeEventList/ServiceFeeEvent', ServiceFeeEvent()) adjustment_events = xm.List('.//AdjustmentEventList/AdjustmentEvent', AdjustmentEvent()) next_token = xm.String('.//NextToken', default=None)
class Promotion(xm.Schema): ignore_missing = True type = xm.String('.//PromotionType') id = xm.String('.//PromotionId') amount = xm.Float('.//PromotionAmount/CurrencyAmount', default=0)
class Dimensions(xm.Schema): units = xm.String('.//Unit') height = xm.Float('.//Height') length = xm.Float('.//Length') width = xm.Float('.//Width')