From 2f2935d06db8d3239b4951b5bd2a40511d55acce Mon Sep 17 00:00:00 2001 From: David Todd Date: Wed, 23 Mar 2016 13:06:15 -0500 Subject: [PATCH] Add range selection ability The original implementation could only search for items that end in a specific date range This makes it so that we can select between a start range, modified range, or the default end range The override could probably use some work as there is currently nothing checking sellerList for any other types and there can only be one --- ebay.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/ebay.py b/ebay.py index 3d4fba1..79327d2 100644 --- a/ebay.py +++ b/ebay.py @@ -230,11 +230,26 @@ def glue(api, sellerList, dateRange={}): res['error']['code'] = '2' res['error']['msg'] = 'dateRange doesn\'t exist or is of wrong type, must be dict' return res + + # Switch statement to check which type of dateRange to search by + # This can be start/mod/end + def rangeType(condition): + # Cast the condition to a string + condition = str(condition) + switch = { + 'start': 'Start', # Covers StartTimeFrom and StartTimeTo - Items that started in this date range + 'mod': 'Mod', # Covers ModTimeFrom and ModTimeTo - Items modified in this date range + 'end': 'End' # Covers EndTimeFrom and EndTimeTo - Items that end within this date range + } + # Return the approiate text or End if no ID matches + return switch.get(condition, 'End') + + # Override the dates in sellerList with values from dateRange, if provided if('from' in dateRange): - sellerList['EndTimeFrom'] = dateRange['from'] + sellerList[rangeType(dateRange['type'])+'TimeFrom'] = dateRange['from'] if('to' in dateRange): - sellerList['EndTimeTo'] = dateRange['to'] + sellerList[rangeType(dateRange['type'])+'TimeTo'] = dateRange['to'] seller = getSeller(api, sellerList) @@ -264,7 +279,12 @@ try: api = Trading(domain=domain, appid=app_id, devid=dev_id, certid=crt_id, token=usr_token, config_file=None, debug=False) # Example usage, returns a dict containing all items of interst (based on the functions above) - print(glue(api=api, sellerList={}, dateRange={'from':today, 'to': '2016-05-26T23:59:59.999Z'})) + itemData = glue(api=api, sellerList={}, dateRange={'from':today, 'to': '2016-05-26T23:59:59.999Z', 'type': 'end'}) + + # Store the itemIDs so that we can use them to check which ones were modified + itemlist = [] + for i in itemData: + itemlist.append(i) except ConnectionError as e: print(e) \ No newline at end of file