Created
March 23, 2017 05:01
-
-
Save kurozumi/3ec110385daeaa528395220ea44ac0bb to your computer and use it in GitHub Desktop.
【Python】eBayのTrading APIを使ってeBayの未発送の注文情報を取得する方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ebaysdk.trading import Connection as Trading | |
from ebaysdk.exception import ConnectionError | |
try: | |
# 各種情報を設定 | |
api = Trading(appid="YOUR_APPID", devid="YOUR_DEVID", certid="YOUR_CERTID", token="YOUR_AUTH_TOKEN") | |
# 注文データ取得 | |
api.execute('GetOrders', { | |
"OrderStatus": "Completed", # 支払い済みの注文のみに絞り込み | |
"OrderRole": "Seller", # セラーの注文のみに絞り込み | |
"NumberOfDays": 1, # 本日から1日遡って注文情報を取得 | |
"IncludeFinalValueFee": True # 手数料データも一緒に取得 | |
}) | |
# 取得した注文データから各種データを取得 | |
for order in api.response.reply.OrderArray.Order: | |
# ShippedTime属性がある場合は発送済みなのでスルー | |
if hasattr(order, "ShippedTime") is True: | |
continue | |
for txn in order.TransactionArray.Transaction: | |
data = { | |
"order_id": order.OrderID, #注文ID | |
"order_item_id": txn.Item.ItemID, #商品ID | |
"created_time": order.CreatedTime, #注文日時 | |
"product_name": txn.Item.Title, # 商品名 | |
"sku": txn.Item.SKU, # SKU | |
"quantity_purchased": txn.QuantityPurchased, # 数量 | |
"price": txn.TransactionPrice, # 単価 | |
"fee": txn.FinalValueFee.value, # 手数料 | |
"shipping_cost": txn.ActualShippingCost.value, # 送料 | |
"ship_name": order.ShippingAddress.Name, | |
"ship_address1": order.ShippingAddress.Street1, | |
"ship_address2": order.ShippingAddress.Street2, | |
"ship_city": order.ShippingAddress.CityName, | |
"ship_state": order.ShippingAddress.StateOrProvince, | |
"ship_postal_code": order.ShippingAddress.PostalCode, | |
"ship_country": order.ShippingAddress.Country, | |
"ship_phone": order.ShippingAddress.Phone | |
} | |
print(data) | |
except ConnectionError as e: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment