0

I'm using IMDbPY and I'd like to output the rating from a specific country. But right now I'm getting all the ratings for all countries.

Here's my Code:

from imdb import IMDb

ia = IMDb()
theMatrix = ia.get_movie_parents_guide('0133093')
print(theMatrix['data']['certification'])

Current Output:

[' Argentina:13', ' Australia:M', ' Belgium:KT/EA', ' Brazil:12', ' (original rating)', ' Brazil:12', ' (re-rating)', ' Brazil:14', ' (re-rating)', ' Brazil:14', ' (2002, TV rating)', ' Canada:14A', ' (Alberta/British Columbia)', ' Canada:PA', ' (Manitoba)', ' Canada:14', ' (Nova Scotia)', ' Canada:AA', ' (Ontario)', ' Canada:13+', ' (Quebec)', ' Denmark:15', ' Finland:K-16', ' France:Tous publics avec avertissement', ' Germany:16', ' Greece:K-8', ' Hong Kong:IIB', ' Hungary:16', ' Iceland:16', ' India:UA', ' (re-rating)', ' India:A', ' (1999, original rating)', ' Ireland:15', ' (theatrical)', ' Ireland:18', ' (video)', ' Israel:PG', ' Italy:T', ' Japan:PG-12', ' Japan:G', ' (2019)', ' Luxembourg:12', ' Malaysia:18SG', ' Mexico:B', ' Netherlands:16', ' (original rating)', ' Netherlands:12', ' (re-rating)', ' New Zealand:M', ' Nigeria:PG', ' Norway:15', ' Peru:14', ' Philippines:PG-13', ' Portugal:M/12', ' Portugal:M/16', ' (Netflix rating)', ' Russia:16+', ' Saudi Arabia:PG', ' Singapore:PG', ' Singapore:PG13', ' (re-rating)', ' South Africa:10', ' South Korea:12', ' Spain:18', ' Sweden:15', ' Switzerland:12', ' (canton of Geneva)', ' Switzerland:12', ' (canton of Vaud)', ' Taiwan:PG-12', ' Thailand:G', ' United Kingdom:15', ' United States:R', ' (certificate #36569)', ' Ukraine:16']

Input:

Argentina
Brazil
United States

Desired output:

Argentina:13
Brazil:12
United States:R
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Lacer
  • 5,668
  • 10
  • 33
  • 45

2 Answers2

0

This is what your are looking for:

from imdb import IMDb
ia = IMDb()
theMatrix = ia.get_movie_parents_guide('0133093')

inp=["Argentina","Brazil","United States"]

print([c[1:] for c in theMatrix['data']['certification'] if c.split(":")[0][1:] in inp])

This is inline for loop, difficult to understand but easy to use. Anyway may use normal loop, like this:

inp=["Argentina","Brazil","United States"]

for c in theMatrix['data']['certification']:
    if c.split(":")[0][1:] in inp:
        print(c[1:])
imxitiz
  • 3,920
  • 3
  • 9
  • 33
0

This is what I was looking for thanks all.

from imdb import IMDb

ia = IMDb()
theMatrix = ia.get_movie_parents_guide('0133093')
ratings = theMatrix['data']['certification']
country = " " + "Brazil"
r = [s for s in ratings if s.startswith(country)]
theRating = r[0]
print (theRating.split(":",1)[1])
Lacer
  • 5,668
  • 10
  • 33
  • 45
  • Are you looking for just "12" ? Because you hadn't told that in your question, you are looking for 12 as output. As you told me, I had gave you answer. And now you are posting answer by printing 12. – imxitiz Jul 19 '21 at 16:43
  • This is your question and your problem I don't wanna bother you, but according to your question, your answer is not giving me answer! Either delete your question or your answer because it will effect future people also. Future people will search for your a llike question and they found it but they will get unnecessary code! – imxitiz Jul 19 '21 at 16:44
  • Your desire output clearly says that you wanna get all values but, your code is just searching for Brazil, and additionally your code is not giving your desire output! I know you can answer your own question but don't answer unnecessary code. Try to edit it and or you may look my answer. I had already gave you answer as your desired output. – imxitiz Jul 19 '21 at 16:48