Skip to content

Instantly share code, notes, and snippets.

@hmarquardt
Created August 6, 2014 14:49
Show Gist options
  • Save hmarquardt/4795b288849d3017df9e to your computer and use it in GitHub Desktop.
Save hmarquardt/4795b288849d3017df9e to your computer and use it in GitHub Desktop.
Ebay -- Complete Order/Add Shipping Info script using the Python EbaySDK (https://github.com/timotheus/ebaysdk-python). This uses v1.0 of the SDK, I've not yet migrated to v2.0 -- Added here because finding example code was hard when I needed to solve this problem. Basically get tracking number and Ebay order number from local Oracle store and u…
# -*- coding: utf-8 -*-
'''
Hank Marquardt
May 26, 2014
'''
import os
import sys
import datetime
import cx_Oracle
from optparse import OptionParser
sys.path.insert(0, '%s/../' % os.path.dirname(__file__))
from common import dump
import ebaysdk
from ebaysdk.utils import getNodeText
from ebaysdk.exception import ConnectionError
from ebaysdk.trading import Connection as Trading
version = 1.0
def init_options():
usage = "usage: %prog [options]"
parser = OptionParser(usage=usage)
parser.add_option("-d", "--debug",
action="store_true", dest="debug", default=False,
help="Enabled debugging [default: %default]")
(opts, args) = parser.parse_args()
return opts, args
def putShipments(opts):
try:
global api
api = Trading(debug=opts.debug,config_file = 'ebay.yaml', warnings=True, timeout=20)
global tycus, cursor
tycus = cx_Oracle.connect(<Insert Oracle DSN here>)
cursor = tycus.cursor()
cursor.execute("alter session set nls_date_format='YYYY-MM-DD'")
sql = '''
select ord_no_ref,carrier_code,ship_track_no,shiped_date from amz_ship_header
where lead_source_code = 'EBAY' and status = 'A'
'''
cursor.execute(sql)
for row in cursor:
ord_no,carrier,tracking_no,ship_date = row
trackingDetail = {'ShipmentTrackingNumber': tracking_no, 'ShippingCarrierUsed': carrier}
shipment = {'ShipmentTrackingDetails': trackingDetail}
api.execute('CompleteSale',{'OrderID': ord_no, 'Paid': 'true', 'Shipped': 'true', 'Shipment': shipment})
print "Processed order: %s with tracking id: %s" % (ord_no,tracking_no)
sql = '''
update amz_ship_header set status = 'S' where lead_source_code = 'EBAY' and status = 'A'
'''
cursor.execute(sql)
tycus.commit()
cursor.close()
tycus.close()
except ConnectionError as e:
print e
if __name__ == "__main__":
(opts, args) = init_options()
print("Ty Ebay shipment processing script ver %s" % version )
putShipments(opts)
@Dhairya40
Copy link

Hello dear please tell me how to change order status using python script?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment