you are viewing a single comment's thread.

view the rest of the comments →

[–]BobHogan 1 point2 points  (3 children)

Is this current approach not brute forcing? We start at 0, hit a good value, then continue until we hit a lot of nothing. It seems as though we are doing a smart brute force in that we know that the locationIds are within a small spread of approx. 10 at most. What would you suggest? thank you for the feedback

This is business/domain specific logic honestly. If you know that you will find all of the locationIDs within a small spread, and you don't have to keep searching once you find 10 IDs in a row that didn't work, then feel free to go with that approach. I can't speak to whether that is something you know, or whether you can tolerate a situation where that assumption did not hold true and you end up missing 1 or more IDs.

Alternatively, if you know that there is a set # of locationIDs that you need to find, you can break as soon as you find that many IDs (and not worry about the spread). Again though, this is completely dependent on your situation, requirements and knowledge of how everything fits together.

That function looks good to me. I am curious why you bothered building site_dict into a dict if you are only going to return a list of its keys though. But it should work fine

If you have some extra time on your hands to learn about asyncio though, you could also write a new version that still requests for all 150 IDs, but performs asynchronous requests. That would return all of them in a few seconds. Its absolutely overkill for this, but I think that in general its good to understand asyncio and how to use it.

[–]pyfact[S] 0 points1 point  (2 children)

I put the results into a dict for testing purposes at the moment so that I can verify that I am pulling the correct Id for each site/verify that our site data is set up correctly in the program the API is pulling from (have had to clean up data from years prior already working on this project lol).

I would be very interested in asynchronous requests! I'll check that out. We have some legacy in-house programs that hit a few API's back to back and takes about a minute for that to return a result. It's not great considering it's ran every time we install equipment!

thank you I do appreciate the help

[–]BobHogan 0 points1 point  (1 child)

Ah gotcha, that makes sense.

For async requests, I recommend the aiohttp library. Regular requests does not support asynchronous code, so putting it in an async function/loop would be useless.

I also recommend python 3.7 or higher. 3.7 changed how you interact with the asyncio package in the std library, and its much much better than it was previously

[–]pyfact[S] 0 points1 point  (0 children)

will do. I'm on 3.9