Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Look at the project you will create in this stage of the course. Plan your work and set up your project.
Suggest Books CSV
Pseudocode Workshop
Check out our workshop on Pseudocode
What Visual Studio extensions are being used?
Here are a lot of the extensions I am using: Meg's Favorite Visual Studio Extensions
Local Setup Steps
- Create a folder for your project
- Open your folder in your IDE
- Open the terminal in your IDE
- Create a virtual environment
- Mac:
python3 -m venv env
- Windows:
python -m venv env
- Mac:
- Activate your environment
- Mac:
source ./env/bin/activate
- Windows:
.\env\Scripts\activate
- Mac:
- Install SQLAlchemy
pip install sqlalchemy
- Create requirements file
pip freeze > requirements.txt
[MUSIC]
0:00
Now that we've learned
a bit about SQLAlchemy,
0:04
it's time to practice our
skills with a small project.
0:07
I have here a file full of great
books to help you on your journey.
0:11
Unfortunately, programming books
don't have very diverse authors, but
0:16
maybe that's something you can help with.
0:20
For those working locally,
0:23
you can download this file from
the teacher's notes below.
0:25
Together, we'll need to make
a database to hold them.
0:28
Then we'll create a console program
that looks something like this.
0:32
It will have a menu where users
can add books to the database.
0:35
You can search for a book.
0:58
And then have the option to edit or
delete it.
1:06
The user can also check some data,
like the most recently published book,
1:13
or how many books there
are in the database.
1:18
Let's plan this out.
1:24
Create a new project folder and
open it in your IDE, or
1:25
open the workspace attached to this video.
1:28
We'll have two files,
one to hold our database logic, and
1:32
the other to hold our application.
1:35
Let's call the database file models.py,
and
1:38
the application file app.py.
1:43
Inside of models.py,
let's think about what we'll need to do.
1:48
We'll need to create a database and
1:55
give it a name, let's say books.db.
1:59
Then we'll need to create a model.
2:05
And if we look at our data,
we'll need to have a title, author,
2:11
date published, and price.
2:15
Cool, in app.py,
we'll need to import our models file.
2:26
Our application will need a main menu.
2:35
.That will have add, search,
2:42
analysis, exit, and view options.
2:46
We'll also need some functions
to add books to the database.
2:51
We'll need to edit books and delete them.
2:59
We'll also need a search function, And
3:08
probably some data cleaning functions too.
3:13
Then we'll need to have a loop,
That's running our program.
3:19
So when the user decides to exit,
the program stops, nice.
3:27
If you wanna plan more and be more
detailed about what you'll be creating,
3:31
then go ahead, this is your project.
3:36
So write as many comments and
pseudocode as you need.
3:39
Let's start by creating
our virtual environment.
3:44
If you're in workspaces,
you can skip this step.
3:49
Also, I'm on a Mac, so if you're on
Windows, check the teacher's notes below
3:52
for a refresher on how to get
your virtual environment working.
3:56
The commands are slightly different.
3:59
I'm gonna run python3 -m venv env.
4:03
And yes, I would like to use it.
4:12
You can see our folder was created,
and then I need to activate it,
4:17
source ./environment/bin/activate,
and it's been activated, perfect.
4:22
Then we can install SQLAlchemy
pip install sqlalchemy.
4:30
That might take a little bit,
nope, was super fast.
4:38
And then I'm going to run pip
freeze > requirements.txt to save
4:41
our one requirement,
which is just SQLAlchemy.
4:47
So create that file, and
you can give it a check by clicking on it,
4:54
SQLAlchemy is in there, awesome.
4:57
We're also going to create a repo for
this project on GitHub.
5:00
Let's create a file called gitignore,
New File, .gitignore.
5:04
Inside, write the name of your
environment folder, for me, it's env.
5:13
Since we don't wanna send all
those files up to our repo,
5:19
these files are just for you.
5:23
When someone wants to run your program,
5:26
they'll use the requirements file to
install SQLAlchemy for themselves.
5:28
I'm also going to add /__pycache__.
5:35
This is a common file that pops
up when you're working in Python.
5:38
You can also see this .vscode file
was added here by Visual Studio.
5:46
That one, we can also ignore.
5:51
And another helpful one to include
if you're on a Mac is .DS_Store.
5:55
This is a file Macs throw
into projects sometimes, and
6:02
it doesn't really hurt
anything by being there.
6:05
But it doesn't help anything either,
so let's just ignore it.
6:09
Save the file, and then in the console,
let's run git init, awesome.
6:12
And now you can see, these are grayed
out because they've been ignored.
6:20
And these are all green because they
are waiting to be added to our repo.
6:24
Next is creating the repo on GitHub.
6:30
You can navigate straight to
github.com/new to create a new
6:35
repo if you're logged in.
6:40
Choose a name for your repo.
6:42
And choose public or
private, it's up to you.
6:51
When you're ready,
click create repository.
6:59
Then we'll need to copy this
code down here, Ctrl+C.
7:05
And let's jump back into our terminal,
Ctrl+V.
7:17
Now let's run git add ., to add all
of the files we've created so far.
7:25
Then we're going to run git commit -m,
7:34
and then our message,
which is initial commit.
7:39
This just means it's
the first thing we've added.
7:46
And it'll show you the five
files that we've added.
7:49
And then you'll want to run
git push origin master.
7:53
Awesome, back in your GitHub repo,
refresh the page.
8:01
And ta-da, all your code is here.
8:05
Now we're ready to get
started on our project.
8:08
You need to sign up for Treehouse in order to download course files.
Sign up