#100DaysOfCode in Python Transcripts
Chapter: Days 91-93: Database access with SQLAlchemy
Lecture: Demo: Introducing our app
0:00 Let's get right into writing some code.
0:03 Now, if you look in the GitHub Repository,
0:05 there's two sets of code here.
0:08 They look exactly the same right now
0:10 but they're going to be very different at the end.
0:12 In this project, we're going to start
0:14 from an existing application.
0:16 One that's already done and all we're going to do
0:19 is add database access to it.
0:22 It's a bit of a trade off that happens to be
0:23 more realistic, more entertaining,
0:25 but slightly more complex by starting with something
0:28 instead of entirely from scratch.
0:29 But we'll isolate the SQLAlchemy pieces really well.
0:32 So this one, this persistent RPS starter,
0:35 this is going to stay in the starter state.
0:37 This one on the other hand, we're going to evolve
0:40 to the final version.
0:41 Now before I open this in PyCharm,
0:43 let me come over here and create a virtual environment.
0:48 And now on MAC OS we can drop it here,
0:50 or on Windows or Linux, you say file, open .directory.
0:54 So let's go through and have a
0:55 quick look at what we got here.
0:56 First, tell PyCharm to chill out on the virtual directory.
1:01 Start up the program.
1:02 So this is the thing that we're going to run.
1:04 Let's just go ahead and run it so you see what happens here,
1:06 in fact, yeah just run it like this.
1:09 So we're going to play, you might've guessed from the RPS,
1:11 Rock Paper Scissors.
1:13 And we're going to use a database to store
1:15 all the players who have played the games,
1:17 all the games that have been played,
1:19 the roles, who has won, who has the highest score,
1:22 we'll do reporting on that so we'll
1:24 sort of show the high score screen
1:26 by just doing a database query
1:27 and order by times they won, things like that.
1:31 It starts out asking what your name is.
1:34 And then we're going to play not rock paper scissors,
1:37 but we're going to play 15-way rock paper scissors.
1:39 So really fun, we have things like:
1:41 the devil, and the dragon, and the sponge, and so on.
1:44 So let's start by throwing standard rock.
1:48 I need that a little higher
1:49 so we can see what's going on here.
1:50 Oh! I've been defeated.
1:52 I threw rock, but the computer threw water.
1:53 Apparently, water beats rock.
1:55 How about fire?
1:57 I'm defeated again, this is not going to be good.
1:59 I'll throw a snake.
2:00 The computer also threw the snake,
2:02 so let's throw eight.
2:06 Paper. They threw tree.
2:08 I'm not looking... I don't think
2:10 it's going to matter what I'll throw
2:12 so let's throw a tree.
2:14 I threw a tree, they threw a scissors,
2:15 I win, but the computer wins 3-1.
2:17 We had one tie, three wins for the computer, one for me.
2:20 Therefore, I lose.
2:22 So we're going to take this game,
2:23 as you can see it lets you play
2:25 but it doesn't show you a high score.
2:27 It has no history of the game.
2:28 If I run it again, it just entirely starts from scratch.
2:32 So we're going to go over here
2:33 and we're going to upgrade this by using SQLAlchemy
2:36 to make it remember.