#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 from our search service and we have created the right URL that works, we already tested that
0:08 in our browser and printed out the text. So the next thing we need to do is convert the text from JSON format into Python dictionaries.
0:16 Now we could use the json library in Python but request has a little goody for us here so we can say results equals response.json,
0:26 that's all we need, it's converted to JSON so we could print out, it's converted to Python dictionary so we could print out the type of results
0:34 and we could also print out the results themselves so if we do that, notice we get a dictionary and here we have the keyword and then we have the hits,
0:42 which is a list of objects that have titles. Let's try to print out, let's try to return those and then at the program level, print them out.
0:51 So, get rid of that and we'll just return results.get hits. Right, we don't care about the extra data, we just want the results.
1:00 And then over here, we're going to get those results back and we can say, for are in results print, let's just print out the title.
1:10 Title is, let's, keep going with the f-strings, huh? Say are .get, now notice we have to treat this as a dictionary, we'll prove this in a moment,
1:23 like that. Okay, let's run this and see what we get. Man, look at that, title. Blade Runner, Maze Runner, Kite Runner,
1:32 something else, Logan's Run and so on. Awesome and we could even do a little bit better, we could say, print, there are length of results,
1:47 movies found, something like that. There are six movies found, okay. Excellent, you might want to do a little test movie,
1:56 1 movie, 2 movies, 0 movies, things like that but we're going to just keep it always plural here. Alright so this is pretty good but notice this,
2:05 I'm not loving this at all and the more we have to write out there, we could say something like that and IMDB score, let's say we're going to write
2:17 that out so we'll say, are .get what, what do you put here? I have no idea. It's completely annoying that you get no help
2:24 about this, we could go look this up but let's go and actually improve that in the next video.