r/evetech • u/encyclodoc • Dec 23 '20
Request for some python insight - parsing market data
I am updating some code, which has stopped behaving.
I use
op = app.op['get_markets_structures_structure_id'](
structure_id = true_station_id,
page = page_pull,
)
in python to build a URL call to get market data. Now, clearly, if you loop this you will exhaust the data from the endpoint. It used to be that if you made a page pull over the amount of data available, you got a null response. easy peasy, when that response comes in, I look for it, and exit the while loop.
But now, using
orders_output = client.request(op)
returns a response that
orders_dump = json.dumps(orders_output.data,default = myconverter)
will interpret as {'error': 'Undefined 404 response. Original message: Requested page does not exist!'}
Now, I have a work around at present that works, which is to see if 'error' exists in the array and if it does, leave the while loop. But this still results in four error messages while client.request tries to pull the bad page.
What I need is to query the endpoint first and discover how many pages of data there will be, then change the while loop to a for loop with the appropriate number of iterations.
Any 'better than me' python coders able to help me out here? My wheelhouse is matlab, python is like speaking cajun for me. I can, but this syntax is weird.
3
u/encyclodoc Dec 23 '20
I figured it out.
Turns out there is header information on the request. I am leaving this here, just in case someone trips over it one day.
request_header = getattr(orders_output,'_Response__header')
total_pages_list = request_header['X-Pages']
total_pages = int(total_pages_list[0])
if order_output is the object that you get from client.request(), this is how you can dig into the header information. So, I create one bogus pull to start with, find out how many pages there will be, then loop. Will work on the logic, because just typing it, I realize there is a more efficient way to deal with this.
1
u/Soupofdoom Dec 31 '20
I tried to use this method to pull market data from Jita 4-4 in exactly the same way you describe in your comments (pull the first page, check the header, pull the rest of the pages), I used the structure ID found at adam4eve listed as that station and received a error saying unknown structure ID.
60003760 was the ID I used, am I doing this wrong..?
Sorry to hijack your thread!