def execute(self, url, data=None, headers=dict(), method=None, parse_response=True): "Executes the HTTP request." log.debug('execute: url=%s data=%s' % (url, data)) if method: self.method = method self._reset() self.build_request(url, data, headers) self.execute_request() if self.parallel: self.parallel._add_request(self) return None self.process_response(parse_response=parse_response) self.error_check() log.debug('total time=%s' % (time.time() - self._time)) return self.response
def __init__(self, obj, verb=None, list_nodes=[], datetime_nodes=[], parse_response=True): self._list_nodes = copy.copy(list_nodes) self._obj = obj if parse_response: try: self._dom = self._parse_xml(obj.content) self._dict = self._etree_to_dict(self._dom) if verb and "Envelope" in self._dict.keys(): elem = self._dom.find("Body").find("%sResponse" % verb) if elem is not None: self._dom = elem self._dict = self._dict["Envelope"]["Body"].get("%sResponse" % verb, self._dict) elif verb: elem = self._dom.find("%sResponse" % verb) if elem is not None: self._dom = elem self._dict = self._dict.get("%sResponse" % verb, self._dict) self.reply = ResponseDataObject(self._dict, datetime_nodes=copy.copy(datetime_nodes)) except lxml.etree.XMLSyntaxError as e: log.debug("response parse failed: %s" % e) self.reply = ResponseDataObject({}, []) else: self.reply = ResponseDataObject({}, [])
def __init__(self, obj, verb=None, list_nodes=[], datetime_nodes=[], parse_response=True): self._list_nodes = copy.copy(list_nodes) self._obj = obj if parse_response: try: self._dom = self._parse_xml(obj.content) self._dict = self._etree_to_dict(self._dom) if verb and 'Envelope' in self._dict.keys(): elem = self._dom.find('Body').find('%sResponse' % verb) if elem is not None: self._dom = elem self._dict = self._dict['Envelope'][ 'Body'].get('%sResponse' % verb, self._dict) elif verb: elem = self._dom.find('%sResponse' % verb) if elem is not None: self._dom = elem self._dict = self._dict.get( '%sResponse' % verb, self._dict) self.reply = ResponseDataObject(self._dict, datetime_nodes=copy.copy(datetime_nodes)) except XMLSyntaxError as e: log.debug('response parse failed: %s' % e) self.reply = ResponseDataObject({}, []) else: self.reply = ResponseDataObject({}, [])
def set(self, order): data = [ ("ID", order.OrderID), ("Status", order.OrderStatus), ("Seller Email", order.SellerEmail), ("Title", order.TransactionArray.Transaction.Item.Title), ("ItemID", order.TransactionArray.Transaction.Item.ItemID), ("QTY", order.TransactionArray.Transaction.QuantityPurchased), ("Payment Method", order.CheckoutStatus.PaymentMethod), ("Payment Date", order.PaidTime), ("Total", (order.Total._currencyID + ' ' + order.Total.value)) ] if order.TransactionArray.Transaction.get('Variation', None): data.append(("SKU", order.TransactionArray.Transaction.Variation.SKU)), data.extend([ ("Shipped Time", order.ShippedTime), ("Shipping Service", order.ShippingServiceSelected) ]) if order.ShippingDetails.get('ShipmentTrackingDetails', None): data.extend([ ("Min Shipping Days", order.ShippingDetails.ShippingServiceOptions.ShippingTimeMin), ("Max Shipping Days", order.ShippingDetails.ShippingServiceOptions.ShippingTimeMax), ("Tracking", order.ShippingDetails.ShipmentTrackingDetails.ShipmentTrackingNumber), ("Carrier", order.ShippingDetails.ShipmentTrackingDetails.ShippingCarrierUsed), ("Cost", (order.ShippingDetails.ShippingServiceOptions.ShippingServiceCost._currencyID, order.ShippingDetails.ShippingServiceOptions.ShippingServiceCost.value)) ]) values_array = map((lambda x: "%s=%s" % (x[0], x[1])), data) log.debug(", ".join(values_array))
def execute(self, verb, data=None, list_nodes=[], verb_attrs=None, files=None): "Executes the HTTP request." log.debug('execute: verb=%s data=%s' % (verb, data)) self._reset() self._list_nodes += list_nodes self._add_prefix(self._list_nodes, verb) if hasattr(self, 'base_list_nodes'): self._list_nodes += self.base_list_nodes self.build_request(verb, data, verb_attrs, files) self.execute_request() if hasattr(self.response, 'content'): self.process_response() self.error_check() log.debug('total time=%s' % (time.time() - self._time)) return self.response
def __init__(self, obj, verb=None, list_nodes=[], datetime_nodes=[], parse_response=True): self._list_nodes = copy.copy(list_nodes) self._obj = obj if parse_response: try: self._dom = self._parse_xml(obj.content) self._dict = self._etree_to_dict(self._dom) if verb and 'Envelope' in self._dict.keys(): elem = self._dom.find('Body').find('%sResponse' % verb) if elem is not None: self._dom = elem self._dict = self._dict['Envelope'][ 'Body'].get('%sResponse' % verb, self._dict) elif verb: elem = self._dom.find('%sResponse' % verb) if elem is not None: self._dom = elem self._dict = self._dict.get( '%sResponse' % verb, self._dict) self.reply = ResponseDataObject(self._dict, datetime_nodes=copy.copy(datetime_nodes)) except XMLSyntaxError as e: log.debug('response parse failed: %s' % e) self._dom = self._parse_xml("<%sResponse>parse error <![CDATA[%s]]></%sResponse>" % (verb, e, verb)) self._dict = self._etree_to_dict(self._dom) self.reply = ResponseDataObject({}, []) else: self.reply = ResponseDataObject({}, [])
def set(self, order): data = [("ID", order.OrderID), ("Status", order.OrderStatus), ("Seller Email", order.SellerEmail), ("Title", order.TransactionArray.Transaction.Item.Title), ("ItemID", order.TransactionArray.Transaction.Item.ItemID), ("QTY", order.TransactionArray.Transaction.QuantityPurchased), ("Payment Method", order.CheckoutStatus.PaymentMethod), ("Payment Date", order.PaidTime), ("Total", (order.Total._currencyID + ' ' + order.Total.value))] if order.TransactionArray.Transaction.get('Variation', None): data.append( ("SKU", order.TransactionArray.Transaction.Variation.SKU)), data.extend([("Shipped Time", order.ShippedTime), ("Shipping Service", order.ShippingServiceSelected)]) if order.ShippingDetails.get('ShipmentTrackingDetails', None): data.extend([ ("Min Shipping Days", order.ShippingDetails.ShippingServiceOptions.ShippingTimeMin), ("Max Shipping Days", order.ShippingDetails.ShippingServiceOptions.ShippingTimeMax), ("Tracking", order.ShippingDetails.ShipmentTrackingDetails. ShipmentTrackingNumber), ("Carrier", order.ShippingDetails.ShipmentTrackingDetails. ShippingCarrierUsed), ("Cost", (order.ShippingDetails.ShippingServiceOptions. ShippingServiceCost._currencyID, order.ShippingDetails. ShippingServiceOptions.ShippingServiceCost.value)) ]) values_array = map((lambda x: "%s=%s" % (x[0], x[1])), data) log.debug(", ".join(values_array))
def execute(self, verb, data=None): "Executes the HTTP request." log.debug('execute: verb=%s data=%s' % (verb, data)) self._reset() self.build_request(verb, data) self.execute_request() if self.response: self.process_response() self.error_check() log.debug('total time=%s' % (time.time() - self._time)) return self
def execute(self, url, data=None, headers=dict(), method=None, parse_response=True): "Executes the HTTP request." log.debug('execute: url=%s data=%s' % (url, data)) if method: self.method=method self._reset() self.build_request(url, data, headers) self.execute_request() if self.parallel: self.parallel._add_request(self) return None self.process_response(parse_response=parse_response) self.error_check() log.debug('total time=%s' % (time.time() - self._time)) return self.response
def run(self): with file_lock("/tmp/.ebaysdk-poller-orders.lock"): log.debug("Started poller %s" % __file__) to_time = datetime.utcnow() # - timedelta(days=4) from_time = to_time - timedelta(hours=self.opts.hours, minutes=self.opts.minutes) ebay_api = Trading(debug=self.opts.debug, config_file=self.opts.yaml, appid=self.opts.appid, certid=self.opts.certid, devid=self.opts.devid, siteid=self.opts.siteid, warnings=False) ebay_api.build_request( 'GetOrders', { 'DetailLevel': 'ReturnAll', 'OrderRole': self.opts.OrderRole, 'OrderStatus': self.opts.OrderStatus, 'Pagination': { 'EntriesPerPage': 25, 'PageNumber': 1, }, 'ModTimeFrom': from_time.strftime('%Y-%m-%dT%H:%M:%S.000Z'), 'ModTimeTo': to_time.strftime('%Y-%m-%dT%H:%M:%S.000Z'), }, None) for resp in ebay_api.pages(): if resp.reply.OrderArray: for order in resp.reply.OrderArray.Order: if self.storage: self.storage.set(order) else: log.debug("storage object not defined") else: log.debug("no orders to process")
def run(self): with file_lock("/tmp/.ebaysdk-poller-orders.lock"): log.debug("Started poller %s" % __file__) to_time = datetime.utcnow() # - timedelta(days=4) from_time = to_time - timedelta(hours=self.opts.hours, minutes=self.opts.minutes) ebay_api = Trading(debug=self.opts.debug, config_file=self.opts.yaml, appid=self.opts.appid, certid=self.opts.certid, devid=self.opts.devid, siteid=self.opts.siteid, warnings=False) ebay_api.build_request('GetOrders', { 'DetailLevel': 'ReturnAll', 'OrderRole': self.opts.OrderRole, 'OrderStatus': self.opts.OrderStatus, 'Pagination': { 'EntriesPerPage': 25, 'PageNumber': 1, }, 'ModTimeFrom': from_time.strftime('%Y-%m-%dT%H:%M:%S.000Z'), 'ModTimeTo': to_time.strftime('%Y-%m-%dT%H:%M:%S.000Z'), }, None) for resp in ebay_api.pages(): if resp.reply.OrderArray: for order in resp.reply.OrderArray.Order: if self.storage: self.storage.set(order) else: log.debug("storage object not defined") else: log.debug("no orders to process")
def debug_callback(self, debug_type, debug_message): log.debug('type: ' + str(debug_type) + ' message' + str(debug_message))
def execute_request(self): log.debug("REQUEST (%s): %s %s" % (self._request_id, self.request.method, self.request.url)) log.debug('headers=%s' % self.request.headers) log.debug('body=%s' % self.request.body) if self.parallel: self.parallel._add_request(self) return None self.response = self.session.send(self.request, verify=True, proxies=self.proxies, timeout=self.timeout, allow_redirects=True) log.debug('RESPONSE (%s):' % self._request_id) log.debug('elapsed time=%s' % self.response.elapsed) log.debug('status code=%s' % self.response.status_code) log.debug('headers=%s' % self.response.headers) log.debug('content=%s' % self.response.text)
def main(opts): with file_lock("/tmp/.ebaysdk-poller-orders.lock"): log.debug("Started poller %s" % __file__) to_time = datetime.utcnow()# - timedelta(days=80) from_time = to_time - timedelta(hours=opts.hours) ebay_api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid, certid=opts.certid, devid=opts.devid, siteid=opts.siteid, warnings=False ) ebay_api.build_request('GetOrders', { 'DetailLevel': 'ReturnAll', 'OrderRole': 'Buyer', 'OrderStatus': 'All', 'Pagination': { 'EntriesPerPage': 25, 'PageNumber': 1, }, 'ModTimeFrom': from_time.strftime('%Y-%m-%dT%H:%M:%S.000Z'), 'ModTimeTo': to_time.strftime('%Y-%m-%dT%H:%M:%S.000Z'), }, None) for resp in ebay_api.pages(): if resp.reply.OrderArray: for order in resp.reply.OrderArray.Order: data = [ ("ID", order.OrderID), ("Status", order.OrderStatus), ("Seller Email", order.SellerEmail), ("Title", order.TransactionArray.Transaction.Item.Title), ("ItemID", order.TransactionArray.Transaction.Item.ItemID), ("QTY", order.TransactionArray.Transaction.QuantityPurchased), ("Payment Method", order.CheckoutStatus.PaymentMethod), ("Payment Date", order.PaidTime), ("Total", (order.Total._currencyID + ' ' + order.Total.value)) ] if order.TransactionArray.Transaction.get('Variation', None): data.append(("SKU", order.TransactionArray.Transaction.Variation.SKU)), data.extend([ ("Shipped Time", order.ShippedTime), ("Shipping Service", order.ShippingServiceSelected) ]) if order.ShippingDetails.get('ShipmentTrackingDetails', None): data.extend([ ("Min Shipping Days", order.ShippingDetails.ShippingServiceOptions.ShippingTimeMin), ("Max Shipping Days", order.ShippingDetails.ShippingServiceOptions.ShippingTimeMax), ("Tracking", order.ShippingDetails.ShipmentTrackingDetails.ShipmentTrackingNumber), ("Carrier", order.ShippingDetails.ShipmentTrackingDetails.ShippingCarrierUsed), ("Cost", (order.ShippingDetails.ShippingServiceOptions.ShippingServiceCost._currencyID, order.ShippingDetails.ShippingServiceOptions.ShippingServiceCost.value)) ]) values_array = map((lambda x: "%s=%s" % (x[0], x[1])), data) log.debug(", ".join(values_array)) # execute SQL here else: log.debug("no orders to process")
def execute_request(self): log.debug("REQUEST (%s): %s %s" \ % (self._request_id, self.request.method, self.request.url)) log.debug('headers=%s' % self.request.headers) log.debug('body=%s' % self.request.body) if self.parallel: self.parallel._add_request(self) return None self.response = self.session.send(self.request, verify=True, proxies=self.proxies, timeout=self.timeout, allow_redirects=True ) log.debug('RESPONSE (%s):' % self._request_id) log.debug('elapsed time=%s' % self.response.elapsed) log.debug('status code=%s' % self.response.status_code) log.debug('headers=%s' % self.response.headers) log.debug('content=%s' % self.response.text)