Created
October 28, 2013 15:54
-
-
Save wrhansen/7199402 to your computer and use it in GitHub Desktop.
Try this for downloading an ActiveInventoryReport using lmslib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This is an example of requesting a report through LMS, in this case we're | |
requesting an ActiveInvenotryReport. | |
NOTE: This code is completely untested at this point, but it should work. | |
""" | |
import uuid | |
import lmslib | |
# Always test with the Sandbox environment first :) | |
env = lmslib.SANDBOX | |
# Create a StartDownloadJob LMSCall object and give it the environment. | |
start_dl = lmslib.StartDownloadJob(env) | |
# I think listing type is one of "Auction", "AuctionAndFixedPrice", "FixedPrice" | |
start_dl.buildRequest("ActiveInventoryReport", uuid.uuid4(), listingType="Auction") | |
response_string = start_dl.sendRequest() # The xml response from eBay. Use this directly if you want to parse it yourself. | |
# If I remember correctly, this step was just used for some minor parsing of the | |
# response to determine if it was a success or error response. | |
# I know the parsing is pretty crap at this point, I never got around to | |
# writing a more complete parser for these responses. | |
response, resp_struct = start_dl.getResponse() | |
# Basically you'll want to parse the response and determine if you can | |
# go on to the next step (which requires a jobId). | |
if response == 'Success': | |
jobId = resp_struct.get('jobId', None) | |
# Now that you've got a jobId, you'll want to retrieve the job's status | |
# until it returns "Completed" and gives you a downloadFileId. | |
job_status = lmslib.GetJobStatus(env) | |
job_status.buildRequest(jobId) | |
downloadFileId = None # Placeholder for download file id. | |
while True: | |
response = job_status.sendRequest() | |
response, resp_struct = job_status.getResponse() | |
if response == "Success": | |
if resp_struct[0].get('jobStatus', None) == 'Completed': | |
# Job is finished, so get the download file ID | |
downloadFileId = resp_struct[0].get('fileReferenceId', None) | |
break | |
time.sleep(5) # Don't spam the ebay server with too many requests at once | |
if downloadFileId: | |
# Now that the report has finished, download it. | |
download_file = lmslib.DownloadFile(env) | |
download_file.buildRequest(jobId, downloadFileId) | |
response = download_file.sendRequest() | |
response, resp_struct = download_file.getResponse() | |
if response == 'Success': | |
print resp_struct # Download should be in the struct. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you after 8 years.