I'm trying to make my script the more pythonic possible. How would a good approach regarding external API and json be?
I'm calling this API (http://docs.themoviedb.apiary.io/) using 'requests'. The thing is that I need to do a bunch of different calls to the API: - http://api.themoviedb.org/3/person << Receive ID and return person info - http://api.themoviedb.org/3/tv << Receive ID and return serie info - http://api.themoviedb.org/3/movie << Receive ID and return movie info - http://api.themoviedb.org/3/search << Receive "Name of person or serie or movie" and return ID I have the following structures: - {query}/{type}?api_key={key}&query={person or tv or movie} - {query}/{id}?api_key={key} - {query}/{id}/credits?api_key={key} - {query}/{id}/season/{season_numer}?api_key={key} - {query}/{id}/season/{season_numer}/episode/{episode_number}?api_key={key} - {query}/{id}/season/{season_numer}/episode/{episode_number}/credits?api_key={key} I'm thinking about creating a class 'API' and have all these URLs and structures there. The thing is that I need to pass my API_KEY and this key will be used for everything, so I just need to pass it once, how can I do that? Yes, I know about class attributes, but the thing is that I will call this class 'API' from different classes and I'll need to instantiate a API obj in each of them, is it a good approach? Inside this 'API' class I would have a __init__ that would receive an API_KEY and different methods, each for a type of query (person, tv, movie, search, credits). Maybe my explanation is a bit confusing but I hope you guys understood, anyway, you can ask for more information if needed! And another thing, What's better, a single module with multiple classes (total lines: ~110) or multiple modules with 1-3 classes (correlated, like class serie, season and episode in the same module, and class person and character in the same module) each? Thanks!
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor