#100DaysOfCode in Python Transcripts
Chapter: Days 43-45: Consuming HTTP services
Lecture: Demo: Data version one: dicts

Login or purchase this course to watch this video and the rest of the course contents.
0:00 So we've seen that we've downloaded the data
0:02 from our search service and we have created
0:04 the right URL that works, we already tested that
0:07 in our browser and printed out the text.
0:09 So the next thing we need to do is convert
0:11 the text from JSON format into Python dictionaries.
0:15 Now we could use the json library in Python
0:19 but request has a little goody for us here
0:21 so we can say results equals response.json,
0:25 that's all we need, it's converted to JSON
0:27 so we could print out, it's converted to Python
0:30 dictionary so we could print out the type of results
0:33 and we could also print out the results themselves
0:35 so if we do that, notice we get a dictionary and here
0:38 we have the keyword and then we have the hits,
0:41 which is a list of objects that have titles.
0:45 Let's try to print out, let's try to return those
0:47 and then at the program level, print them out.
0:50 So, get rid of that and we'll just return
0:52 results.get hits.
0:56 Right, we don't care about the extra data,
0:57 we just want the results.
0:59 And then over here, we're going to get those results back
1:03 and we can say, for are in results print,
1:07 let's just print out the title.
1:09 Title is, let's, keep going with the f-strings, huh?
1:15 Say are .get, now notice we have to treat this
1:18 as a dictionary, we'll prove this in a moment,
1:22 like that.
1:23 Okay, let's run this and see what we get.
1:27 Man, look at that, title.
1:29 Blade Runner, Maze Runner, Kite Runner,
1:31 something else, Logan's Run and so on.
1:34 Awesome and we could even do a little
1:36 bit better, we could say, print,
1:39 there are length of results,
1:46 movies found, something like that.
1:50 There are six movies found, okay.
1:53 Excellent, you might want to do a little test movie,
1:55 1 movie, 2 movies, 0 movies, things like that
1:58 but we're going to just keep it always plural here.
2:01 Alright so this is pretty good but notice this,
2:04 I'm not loving this at all and the more we have to write
2:07 out there, we could say something like that and IMDB score,
2:15 let's say we're going to write
2:16 that out so we'll say, are .get what,
2:18 what do you put here?
2:20 I have no idea.
2:21 It's completely annoying that you get no help
2:23 about this, we could go look this up but let's go
2:26 and actually improve that in the next video.