0

I am using IMDBpy to fetch release date of an episode of any tv series using this function.

episode_Release_date = ia.get_movie_release_dates(episode_id)

Now this function is returning this value -

{'data': {'raw release dates': [{'country': 'Argentina', 'date': '30 July 2017'}, {'country': 'USA', 'date': '30 July 2017'}, {'country': 'Germany', 'date': '31 July 2017', 'notes': ' (limited)'}, {'country': 'UK', 'date': '31 July 2017'}, {'country': 'Italy', 'date': '31 July 2017'}], 'release dates': ['Argentina::30 July 2017', 'USA::30 July 2017', 'Germany::31 July 2017 (limited)', 'UK::31 July 2017', 'Italy::31 July 2017']}, 'titlesRefs': {}, 'namesRefs': {}, 'info sets': ('release dates', 'akas')}

Now I only want data related to USA. How to access USA's release date in this list.

API Function -

def get_movie_release_dates(self, movieID):
        cont = self._retrieve(self.urls['movienter code heree_main'] % movieID + 'releaseinfo')
        ret = self.mProxy.releasedates_parser.parse(cont)
        ret['info sets'] = ('release dates', 'akas')
        return ret

I'm new to python and just a beginner.

vash_the_stampede
  • 4,590
  • 1
  • 8
  • 20

2 Answers2

1

Using pprint could be helpful in visualizing when navigating nested dictionaries

for i in ret['data']['release dates']:
    if 'USA' in i:
        print(i)
# USA::30 July 2017
vash_the_stampede
  • 4,590
  • 1
  • 8
  • 20
1

Looks like return value is a json string but I am not sure why "(", ")" are present in the returned value. Assuming that it's a proper json value, json module can be used to parse and get the desired value.

If you are searching for raw released dates -

for relEntry in episode_Release_date['data']['raw release dates']:
    if relEntry['country'] == "USA":
        print(relEntry) 

And if you are searching in release dates -

for relEntry in episode_Release_date['data']['release dates']:
    if "USA" in relEntry:
        print(relEntry)   
Ajay Srivastava
  • 1,151
  • 11
  • 15