Now that we have our first function, I wanted to mention again code versioning.
It is best practice that we commit changes after we have done some meaningful change in our code base,
such as adding a new function, fixing a bug, or refactoring.
We have already seen the steps to git add, commit and push.
But before we do so, we have one slight issue in our code.
We have the API key which is sensitive information.
If we were to commit it to our public GitHub repository, everyone would have access to it.
This is not something we want and goes against best practices.
So before we push to GitHub we can do a few changes to the function.
And here we introduce the dot env file.
I will mention that there are other ways of handling sensitive information, but the dot env provides
a simple and effective way of doing this.
So first we create a dot env file and add the API key here.
In order to be able to code a variable from the env.
When we execute the video stats py script, we need to install a python module called Python env.
So let's do that using pip.
So first we actually need to activate the Venv.
Now the Venv is activated.
And now we can do the pip install.
So pip install python dot env.
Once you have installed the library we can modify the code slightly as follows.
First we add some library imports.
We will be needing these two.
And also now we can reference the API key using the OS dot get env format.
So this will get the API key from the env file.
Let's make sure that the name inside the brackets matches with the name in mv file.
One last important step is to specify the path from where the Python script should read the file.
This can be done using the load function from the EMV module we just imported.
The only argument we need to specify is the path to the EMV file.
Since the env file is in the same directory of the Python script, you can see this here.
We write dot at the beginning, indicating the current directory forward slash and the name of the env
file, which is the dot env.
So we had to write this out.
It would look something like this.
Specify the path as we said dot at the beginning which specifies the current directory and then the
dot env file.
And that's it.
Let's test it out to make sure it works.
Let me just check here that the print is uncommented.
Save and then run.
And there we have it.
Now that we have our sensitive variables inside of EMV, what is left is to include this file in the
dot get ignore.
So when we come to push the Python script we have worked on, the API key won't be sitting in our Python
script.
Let's do that right now.
So we go ignore and add dot EMV.
Now we can push our changes to GitHub.
So git add git commit.
We can say edit dot env to git ignore.
Save the api key inside dot env file.
One final thing is to push.
That's what I wanted to show you for the dot env file.
And now we can proceed to part two of the lecture.