1212from ebaysdk import log
1313
1414
15- def main (opts ):
16-
17- with file_lock ("/tmp/.ebaysdk-poller-orders.lock" ):
18- log .debug ("Started poller %s" % __file__ )
19-
20- to_time = datetime .utcnow ()# - timedelta(days=80)
21- from_time = to_time - timedelta (hours = opts .hours )
22-
23- ebay_api = Trading (debug = opts .debug , config_file = opts .yaml , appid = opts .appid ,
24- certid = opts .certid , devid = opts .devid , siteid = opts .siteid , warnings = False
25- )
26-
27- ebay_api .build_request ('GetOrders' , {
28- 'DetailLevel' : 'ReturnAll' ,
29- 'OrderRole' : 'Buyer' ,
30- 'OrderStatus' : 'All' ,
31- 'Pagination' : {
32- 'EntriesPerPage' : 25 ,
33- 'PageNumber' : 1 ,
34- },
35- 'ModTimeFrom' : from_time .strftime ('%Y-%m-%dT%H:%M:%S.000Z' ),
36- 'ModTimeTo' : to_time .strftime ('%Y-%m-%dT%H:%M:%S.000Z' ),
37- }, None )
38-
39- for resp in ebay_api .pages ():
40-
41- if resp .reply .OrderArray :
42-
43- for order in resp .reply .OrderArray .Order :
44-
45- data = [
46- ("ID" , order .OrderID ),
47- ("Status" , order .OrderStatus ),
48- ("Seller Email" , order .SellerEmail ),
49- ("Title" , order .TransactionArray .Transaction .Item .Title ),
50- ("ItemID" , order .TransactionArray .Transaction .Item .ItemID ),
51- ("QTY" , order .TransactionArray .Transaction .QuantityPurchased ),
52- ("Payment Method" , order .CheckoutStatus .PaymentMethod ),
53- ("Payment Date" , order .PaidTime ),
54- ("Total" , (order .Total ._currencyID + ' ' + order .Total .value ))
55- ]
56-
57- if order .TransactionArray .Transaction .get ('Variation' , None ):
58- data .append (("SKU" , order .TransactionArray .Transaction .Variation .SKU )),
59-
60- data .extend ([
61- ("Shipped Time" , order .ShippedTime ),
62- ("Shipping Service" , order .ShippingServiceSelected )
63- ])
64-
65- if order .ShippingDetails .get ('ShipmentTrackingDetails' , None ):
66- data .extend ([
67- ("Min Shipping Days" , order .ShippingDetails .ShippingServiceOptions .ShippingTimeMin ),
68- ("Max Shipping Days" , order .ShippingDetails .ShippingServiceOptions .ShippingTimeMax ),
69- ("Tracking" , order .ShippingDetails .ShipmentTrackingDetails .ShipmentTrackingNumber ),
70- ("Carrier" , order .ShippingDetails .ShipmentTrackingDetails .ShippingCarrierUsed ),
71- ("Cost" , (order .ShippingDetails .ShippingServiceOptions .ShippingServiceCost ._currencyID , order .ShippingDetails .ShippingServiceOptions .ShippingServiceCost .value ))
72- ])
73-
74- values_array = map ((lambda x : "%s=%s" % (x [0 ], x [1 ])), data )
75- log .debug (", " .join (values_array ))
76-
77- # execute SQL here
78-
79- else :
80- log .debug ("no orders to process" )
15+ class Storage (object ):
16+ def set (self , order ):
17+ data = [
18+ ("ID" , order .OrderID ),
19+ ("Status" , order .OrderStatus ),
20+ ("Seller Email" , order .SellerEmail ),
21+ ("Title" , order .TransactionArray .Transaction .Item .Title ),
22+ ("ItemID" , order .TransactionArray .Transaction .Item .ItemID ),
23+ ("QTY" , order .TransactionArray .Transaction .QuantityPurchased ),
24+ ("Payment Method" , order .CheckoutStatus .PaymentMethod ),
25+ ("Payment Date" , order .PaidTime ),
26+ ("Total" , (order .Total ._currencyID + ' ' + order .Total .value ))
27+ ]
28+
29+ if order .TransactionArray .Transaction .get ('Variation' , None ):
30+ data .append (("SKU" , order .TransactionArray .Transaction .Variation .SKU )),
31+
32+ data .extend ([
33+ ("Shipped Time" , order .ShippedTime ),
34+ ("Shipping Service" , order .ShippingServiceSelected )
35+ ])
36+
37+ if order .ShippingDetails .get ('ShipmentTrackingDetails' , None ):
38+ data .extend ([
39+ ("Min Shipping Days" , order .ShippingDetails .ShippingServiceOptions .ShippingTimeMin ),
40+ ("Max Shipping Days" , order .ShippingDetails .ShippingServiceOptions .ShippingTimeMax ),
41+ ("Tracking" , order .ShippingDetails .ShipmentTrackingDetails .ShipmentTrackingNumber ),
42+ ("Carrier" , order .ShippingDetails .ShipmentTrackingDetails .ShippingCarrierUsed ),
43+ ("Cost" , (order .ShippingDetails .ShippingServiceOptions .ShippingServiceCost ._currencyID , order .ShippingDetails .ShippingServiceOptions .ShippingServiceCost .value ))
44+ ])
45+
46+ values_array = map ((lambda x : "%s=%s" % (x [0 ], x [1 ])), data )
47+ log .debug (", " .join (values_array ))
48+
49+
50+ class Orders (object ):
51+
52+ def __init__ (self , opts , storage = None ):
53+ self .opts = opts
54+ self .storage = storage
55+
56+ def run (self ):
57+
58+ with file_lock ("/tmp/.ebaysdk-poller-orders.lock" ):
59+ log .debug ("Started poller %s" % __file__ )
60+
61+ to_time = datetime .utcnow () #- timedelta(days=80)
62+ from_time = to_time - timedelta (hours = self .opts .hours )
63+
64+ ebay_api = Trading (debug = self .opts .debug , config_file = self .opts .yaml ,
65+ appid = self .opts .appid , certid = self .opts .certid ,
66+ devid = self .opts .devid , siteid = self .opts .siteid ,
67+ warnings = False )
68+
69+ ebay_api .build_request ('GetOrders' , {
70+ 'DetailLevel' : 'ReturnAll' ,
71+ 'OrderRole' : self .opts .OrderRole ,
72+ 'OrderStatus' : 'All' ,
73+ 'Pagination' : {
74+ 'EntriesPerPage' : 25 ,
75+ 'PageNumber' : 1 ,
76+ },
77+ 'ModTimeFrom' : from_time .strftime ('%Y-%m-%dT%H:%M:%S.000Z' ),
78+ 'ModTimeTo' : to_time .strftime ('%Y-%m-%dT%H:%M:%S.000Z' ),
79+ }, None )
80+
81+ for resp in ebay_api .pages ():
82+
83+ if resp .reply .OrderArray :
84+
85+ for order in resp .reply .OrderArray .Order :
86+ if self .storage :
87+ self .storage .set (order )
88+ else :
89+ log .debug ("storage object not defined" )
90+ else :
91+ log .debug ("no orders to process" )
8192
8293
8394if __name__ == '__main__' :
84- (opts , args ) = parse_args ("usage: python -u -m ebaysdk.poller.orders [options]" )
85- main (opts )
95+ (opts , args ) = parse_args ("usage: python -m ebaysdk.poller.orders [options]" )
96+
97+ poller = Orders (opts , Storage ())
98+ poller .run ()
0 commit comments