#100DaysOfCode in Python Transcripts
Chapter: Days 43-45: Consuming HTTP services
Lecture: Your turn: Day 2
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Second day of this section is going to
0:03
actually be to work with
0:04
an entirely different API,
0:06
but another one around the podcast
0:08
just to keep it simple and stable.
0:10
So what your going to do is we're going to
0:12
interact with this search.talkpython.fm
0:15
Now if you're over here and you're
0:16
on Talk Python,
0:17
and you try to search,
0:19
you could say "I would like to search for
0:21
let's say, a 100DaysOfCode".
0:22
Pull that up you can see
0:24
it went back and found a couple of elements,
0:25
an episode and a transcript,
0:27
and it did this in a ridiculously
0:29
fast period of time.
0:31
But there's actually an API underneath here
0:34
there's JSON API,
0:35
and you can write queries you
0:36
can search yourself right?
0:37
it's open, and searchable for you
0:38
and it's exactly like what you've been
0:41
working with.
0:42
So let's go over here and play
0:43
with this a little bit.
0:45
Click on this, and see the raw data,
0:47
This is what you get back if you search for
0:50
tests, so whatever you do is you put
0:52
the little query string pieces there,
0:54
so we'll put a100DaysOfCode,
0:56
uh, and it's going to come back
0:57
Firefox tries to make that response pretty,
0:59
but it's going to come back looking
1:00
something like this.
1:02
Alright, so this is the API we're
1:04
going to work with.
1:05
So the first thing you're donna do is
1:07
explore the API imposement,
1:09
and your goal for the day
1:11
is to create a program that
1:12
does the following:
1:14
It gets a search word from the user,
1:16
It calls the search service using that
1:18
API we just looked at,
1:20
it makes sure the response
1:22
from the server was okay so request.
1:24
response.raise_for_status I believe,
1:28
And then you want to return
1:29
just a basic dictionary of the results,
1:32
and use that to list out the titles.
1:35
So it should look something like this on Day 2.
1:37
Run your program, it has a
1:38
little header if you want,
1:39
ask the user for some search terms
1:40
and it says "Boom. These are the titles."