WEBVTT

00:04.160 --> 00:08.000
Now that we have our first function, I wanted to mention again code versioning.

00:08.600 --> 00:13.760
It is best practice that we commit changes after we have done some meaningful change in our code base,

00:13.760 --> 00:17.400
such as adding a new function, fixing a bug, or refactoring.

00:17.440 --> 00:20.760
We have already seen the steps to git add, commit and push.

00:21.200 --> 00:24.680
But before we do so, we have one slight issue in our code.

00:24.680 --> 00:27.160
We have the API key which is sensitive information.

00:27.160 --> 00:31.720
If we were to commit it to our public GitHub repository, everyone would have access to it.

00:32.240 --> 00:35.760
This is not something we want and goes against best practices.

00:35.960 --> 00:39.600
So before we push to GitHub we can do a few changes to the function.

00:39.600 --> 00:42.000
And here we introduce the dot env file.

00:42.320 --> 00:48.400
I will mention that there are other ways of handling sensitive information, but the dot env provides

00:48.400 --> 00:51.200
a simple and effective way of doing this.

00:51.360 --> 00:55.000
So first we create a dot env file and add the API key here.

01:01.680 --> 01:04.480
In order to be able to code a variable from the env.

01:04.520 --> 01:11.600
When we execute the video stats py script, we need to install a python module called Python env.

01:12.320 --> 01:13.920
So let's do that using pip.

01:14.080 --> 01:16.640
So first we actually need to activate the Venv.

01:18.800 --> 01:20.680
Now the Venv is activated.

01:21.720 --> 01:23.920
And now we can do the pip install.

01:23.920 --> 01:29.160
So pip install python dot env.

01:30.040 --> 01:34.200
Once you have installed the library we can modify the code slightly as follows.

01:34.240 --> 01:37.360
First we add some library imports.

01:37.640 --> 01:38.960
We will be needing these two.

01:40.120 --> 01:46.720
And also now we can reference the API key using the OS dot get env format.

01:46.880 --> 01:51.760
So this will get the API key from the env file.

01:51.960 --> 01:56.760
Let's make sure that the name inside the brackets matches with the name in mv file.

01:56.960 --> 02:02.650
One last important step is to specify the path from where the Python script should read the file.

02:03.130 --> 02:08.250
This can be done using the load function from the EMV module we just imported.

02:08.570 --> 02:12.330
The only argument we need to specify is the path to the EMV file.

02:12.450 --> 02:17.850
Since the env file is in the same directory of the Python script, you can see this here.

02:17.890 --> 02:24.770
We write dot at the beginning, indicating the current directory forward slash and the name of the env

02:24.770 --> 02:26.490
file, which is the dot env.

02:27.050 --> 02:28.850
So we had to write this out.

02:28.890 --> 02:30.570
It would look something like this.

02:33.730 --> 02:40.570
Specify the path as we said dot at the beginning which specifies the current directory and then the

02:40.570 --> 02:41.530
dot env file.

02:41.530 --> 02:42.370
And that's it.

02:42.610 --> 02:44.450
Let's test it out to make sure it works.

02:46.010 --> 02:50.010
Let me just check here that the print is uncommented.

02:50.850 --> 02:52.490
Save and then run.

02:54.050 --> 02:55.090
And there we have it.

02:56.170 --> 03:01.970
Now that we have our sensitive variables inside of EMV, what is left is to include this file in the

03:01.970 --> 03:02.850
dot get ignore.

03:03.050 --> 03:08.530
So when we come to push the Python script we have worked on, the API key won't be sitting in our Python

03:08.530 --> 03:09.130
script.

03:09.650 --> 03:10.690
Let's do that right now.

03:10.890 --> 03:14.490
So we go ignore and add dot EMV.

03:16.570 --> 03:18.930
Now we can push our changes to GitHub.

03:19.770 --> 03:23.410
So git add git commit.

03:24.850 --> 03:30.650
We can say edit dot env to git ignore.

03:32.290 --> 03:38.410
Save the api key inside dot env file.

03:42.170 --> 03:43.850
One final thing is to push.

03:46.850 --> 03:49.210
That's what I wanted to show you for the dot env file.

03:49.210 --> 03:51.850
And now we can proceed to part two of the lecture.
