Closed b-gonzalez closed 7 months ago
I feel like this is a complicated example for what is a very simple API with a single function. It's more of an example of how to work with pandas and CSVs, than how to work with this API.
To me the only possibly complicated thing is the returned data structure as it have a lot of fields, but they are all in readme and docs already.
That's fair. I do think doing that this subsection of code is at least directly relevant to using the API
from simplejustwatchapi.query import MediaEntry, Offer
movies = {'The Matrix':'https://www.justwatch.com/us/movie/the-matrix'}
for movie in movies.keys():
movie_url = movies[movie]
#need to remove "www."" because url in media entry will not contain it
temp_url = movie_url.replace("www.","")
MediaEntries = search(movie, "US", "en", 15, False)
media_entry = None
for me in MediaEntries:
#check if media entry matches URL and exit loop once you have a match
if me.url == temp_url:
media_entry = me
break
#additonal processing here
If you don't match the JustWatch URL to media entry URL, you can get a bunch of different MediaEntries for movies that are not related to the film you're looking for. For something like The Matrix which may only have one entry this may be fine. But for movies with more common names thing could be more difficult.
But this is your project at the end of the day. So if that's not something you want I will respect your decision.
I added an example to the read me showing how you'd use this API and write the data to a CSV file using a DataFrame library like Pandas or optionally Polars