mirror of
https://github.com/c0de-archive/ebay-testing.git
synced 2024-12-22 12:42:41 +00:00
Add start check in setDateRange, begin Parallel experiments
Give the setDateRange function the ability to chose an arbitrary date to start at, defaulting to today Parallel will help us dump and update a lot of information at once in the future
This commit is contained in:
parent
0394f2c2b8
commit
02be8b52bd
62
ebay.py
62
ebay.py
@ -1,6 +1,11 @@
|
|||||||
# Imports first
|
# Imports first
|
||||||
# This is the sdk found at https://github.com/timotheus/ebaysdk-python
|
# This is the sdk found at https://github.com/timotheus/ebaysdk-python
|
||||||
from ebaysdk.trading import Connection as Trading
|
from ebaysdk.trading import Connection as Trading
|
||||||
|
from ebaysdk.exception import ConnectionError, ConnectionResponseError
|
||||||
|
|
||||||
|
# Parallel requires Gevent and Grequests modules to be available on the server (requires at least 2.7.5)
|
||||||
|
from ebaysdk.parallel import Parallel
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
# Application Settings
|
# Application Settings
|
||||||
@ -12,9 +17,53 @@ domain = 'api.sandbox.ebay.com'
|
|||||||
# User Identification
|
# User Identification
|
||||||
usr_token = ''
|
usr_token = ''
|
||||||
|
|
||||||
# Don't get items that are ending today
|
# Creates a dateRange list for use with glue
|
||||||
today = datetime.datetime.today()
|
def setDateRange(days=None, start=None, rangeType=None):
|
||||||
today = today.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
# Default to searching for listings ending today
|
||||||
|
if days == None:
|
||||||
|
days = 0
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
days = int(days)
|
||||||
|
except ValueError:
|
||||||
|
days = 0
|
||||||
|
if rangeType == None:
|
||||||
|
rangeType = 'end'
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
rangeType = str(rangeType)
|
||||||
|
# This shouldn't happen, but good to have a check out of the gates
|
||||||
|
except ValueError:
|
||||||
|
rangeType = 'end'
|
||||||
|
|
||||||
|
if start == None:
|
||||||
|
# Begin the search at the current timestamp
|
||||||
|
today = datetime.datetime.today()
|
||||||
|
elif type(start) == 'datetime.datetime':
|
||||||
|
today = start
|
||||||
|
elif type(start) == 'str':
|
||||||
|
try:
|
||||||
|
# Try to cast the string to the datetime type
|
||||||
|
today = datetime.datetime.strptime(start, '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||||
|
except ValueError:
|
||||||
|
# The string wasn't valid to become a datetime, set to today
|
||||||
|
today = datetime.datetime.today()
|
||||||
|
else:
|
||||||
|
today = datetime.datetime.today()
|
||||||
|
|
||||||
|
|
||||||
|
# Set the days argument to search forward more than one day
|
||||||
|
delta = datetime.timedelta(days)
|
||||||
|
|
||||||
|
# End the search at the future timestamp
|
||||||
|
future = today+delta
|
||||||
|
# Convert our dates into a format that ebay can recognize (ISO 8601)
|
||||||
|
today = today.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
|
||||||
|
future = future.strftime("%Y-%m-%dT23:59:59.999Z")
|
||||||
|
|
||||||
|
# If we want to manipulate either today or future, the following converts from a string back into a datetime object
|
||||||
|
# datetime.datetime.strptime(today, '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||||
|
return {'from': today, 'to': future, 'type': rangeType}
|
||||||
|
|
||||||
# Here are the error codes that we currently have
|
# Here are the error codes that we currently have
|
||||||
# None - No events have happened yet
|
# None - No events have happened yet
|
||||||
@ -291,15 +340,18 @@ def glue(api, sellerList, dateRange={}):
|
|||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
api = Trading(domain=domain, appid=app_id, devid=dev_id, certid=crt_id, token=usr_token, config_file=None, debug=False)
|
p = Parallel()
|
||||||
|
|
||||||
|
api = Trading(domain=domain, appid=app_id, devid=dev_id, certid=crt_id, token=usr_token, config_file=None, debug=False, parellel=p)
|
||||||
|
|
||||||
# Example usage, returns a dict containing all items of interst (based on the functions above)
|
# Example usage, returns a dict containing all items of interst (based on the functions above)
|
||||||
itemData = glue(api=api, sellerList={}, dateRange={'from':today, 'to': '2016-05-26T23:59:59.999Z', 'type': 'end'})
|
itemData = glue(api=api, sellerList={'Pagination': {'EntriesPerPage':'100', 'PageNumber':'1'}}, dateRange=setDateRange(0, 'end'))
|
||||||
|
|
||||||
# Store the itemIDs so that we can use them to check which ones were modified
|
# Store the itemIDs so that we can use them to check which ones were modified
|
||||||
itemlist = []
|
itemlist = []
|
||||||
for i in itemData:
|
for i in itemData:
|
||||||
itemlist.append(i)
|
itemlist.append(i)
|
||||||
|
|
||||||
|
|
||||||
except ConnectionError as e:
|
except ConnectionError as e:
|
||||||
print(e)
|
print(e)
|
Loading…
Reference in New Issue
Block a user