1
00:00:00,570 --> 00:00:05,340
Hey, in this video, I'll show you the code which constructs this website.

2
00:00:06,120 --> 00:00:07,770
And the code is here.

3
00:00:08,189 --> 00:00:11,820
So it's 27, 26 lines of code.

4
00:00:11,850 --> 00:00:15,000
And I'll go through the code now and explain you what it does.

5
00:00:15,000 --> 00:00:18,390
So we need the request library and the stream little libraries.

6
00:00:19,500 --> 00:00:23,190
And here I prepared the API key.

7
00:00:23,190 --> 00:00:25,590
This one in here and the URL.

8
00:00:25,920 --> 00:00:26,700
The URL.

9
00:00:26,700 --> 00:00:28,230
I place it as a string.

10
00:00:28,230 --> 00:00:30,630
So split in two lines.

11
00:00:31,440 --> 00:00:32,759
And it's an F string.

12
00:00:32,770 --> 00:00:34,500
The second part.

13
00:00:35,160 --> 00:00:36,660
The API key goes here.

14
00:00:36,900 --> 00:00:41,710
You could also place it directly in here without using an f string.

15
00:00:41,730 --> 00:00:42,990
Either way, it's fine.

16
00:00:43,800 --> 00:00:51,120
Then I created a response object using the request that gets providing that URL.

17
00:00:51,120 --> 00:00:56,160
So the URL pointing to the astronomy picture of the API.

18
00:00:56,430 --> 00:00:58,500
And I got the data as JSON.

19
00:00:59,550 --> 00:01:03,990
So at this point, if I debug this program.

20
00:01:06,480 --> 00:01:08,830
Just to show you the data look like this.

21
00:01:08,850 --> 00:01:12,570
So it has the explanation, the title, and the URL.

22
00:01:14,000 --> 00:01:17,840
So that's it up to here.

23
00:01:17,840 --> 00:01:19,820
And then we have.

24
00:01:25,280 --> 00:01:26,510
These three lines.

25
00:01:26,510 --> 00:01:33,350
So I decided to extract the title of the image, the URL of the image, and the explanation of the image

26
00:01:33,350 --> 00:01:35,000
in three different variables.

27
00:01:38,060 --> 00:01:39,470
So this is not necessary.

28
00:01:39,470 --> 00:01:44,270
You could also use this directly further down without having variables.

29
00:01:44,270 --> 00:01:45,830
Either way is also fine.

30
00:01:46,550 --> 00:01:49,220
And then I downloaded the image here.

31
00:01:49,220 --> 00:01:57,260
So first I decided to create a variable where I stole the file path that the image that the downloaded

32
00:01:57,260 --> 00:01:58,760
image will contain.

33
00:01:59,090 --> 00:02:05,810
So I've used quite a lot of variables here in the code, and then I have this response object.

34
00:02:05,810 --> 00:02:11,780
It's another request that we're doing, but this time we're requesting the image URL.

35
00:02:11,960 --> 00:02:20,510
The first time it was the URL of the API, but now we get the image URL, which was inside the data

36
00:02:20,510 --> 00:02:22,760
which we extract from the API.

37
00:02:23,340 --> 00:02:24,980
And then I opened.

38
00:02:26,220 --> 00:02:29,250
A new file using the WB mode.

39
00:02:29,550 --> 00:02:31,530
So that's the name of the file.

40
00:02:31,560 --> 00:02:33,350
IMG img.

41
00:02:33,660 --> 00:02:40,800
And I wrote the contents of the response object, which I created in here.

42
00:02:41,670 --> 00:02:43,520
And then this is about streamlined.

43
00:02:43,530 --> 00:02:47,220
So I wrote a title which corresponds to that.

44
00:02:47,580 --> 00:02:50,850
I wrote the image using that image file path.

45
00:02:52,640 --> 00:02:53,900
To render the image.

46
00:02:54,170 --> 00:02:58,040
And finally, I wrote the explanation using a right method.

47
00:02:59,120 --> 00:03:00,320
So that's the code.

48
00:03:00,350 --> 00:03:01,310
It's quite simple.

49
00:03:01,910 --> 00:03:03,260
And that's about this video.

50
00:03:03,290 --> 00:03:04,310
Thanks to you.

