elisaado / somtoday-api-docs

Documentation for the SOMtoday API
69 stars 15 forks source link

Update README.md #4

Closed joosthoi1 closed 4 years ago

elisaado commented 5 years ago

Hey, good to see someone look into the API.

Your pull request looks good but, how did you discover the format?

Also, if you know, could you explain what it does?

joosthoi1 commented 5 years ago

Yeah, I found it when I was creating my own api wrapper in python: https://github.com/joosthoi1/SOM-wrapper-project basically i came to the part of getting grades and found that you will only get back a max of 100 results, the days that followed i was eagerly trying to find a solution and then i found this: https://github.com/RickBakkr/SOMtoday/issues/15. turned out someone else had the solution, though he didnt understand what he meant, so I had a little private conversation with him on instagram and he changed his comment accordingly.

basically, as you can see in this next pixture of the headers you get from the requets, you can only get 100 result max: https://imgur.com/4QPNRqw

we cannot change this max value, but if we look up a bit in the headers (https://imgur.com/UVyels4) we can see the format is "items=[LowerBound]-[UpperBound]" you are still tied to the 100 limit, but now you can do 100-200 aswell.

Let me make clear that I did not find this on my own and the person from the issue basically did all the work, just thought I'd put it in the api docs.

Let me know if this is enough information.

Joost

elisaado commented 5 years ago

Aha I see

elisaado commented 5 years ago

So the default value of range is 0-100?

joosthoi1 commented 5 years ago

Exactly, thats why you will only get 100 dict entrys, though you can never get more since they have a max of 100, i believe setting the range to something like 0-200 will still only get you the first 100 results, in my own script i fixed this by doing something like this:

x = 0
while True:
    data = requests.get(whatever blah blah, headers = {
        Blah,
        range = f'items={x*100}-{(x+1)*100}'
    })
    if not data.text:
        break
    else:
        *parse data*
        x += 1

So basically i go through the entries until the list turns empty, did this code on the top of my heas so prob has errors. Also, make sure items=[]-[] is connected since otherwise i dont think it works

joosthoi1 commented 5 years ago

actually, if you want you can add me on discord so we can also change the resultaten json so its correct lol my discord tag is joosthoi1#0460 add me if you want

elisaado commented 5 years ago

@joosthoi1, sure! I sent you a friend request

elisaado commented 4 years ago

Thank you @joosthoi1!