#100DaysOfWeb in Python Transcripts
Chapter: Days 33-36: Database access with SQLAlchemy
Lecture: Importing starter data

Login or purchase this course to watch this video and the rest of the course contents.
0:00 So, we think we have our data access layer working
0:02 but we have no data. We can't really test it.
0:05 So, let's go and add one more file.
0:07 And this one I'm going to drop in and just talk you through
0:09 because it's super tedious to write.
0:11 So, what this is going to do is it's going to import data
0:16 only if those particular tables are empty.
0:18 So, it's going to import only the user's table
0:21 if there's no users, or the scooters if there's no scooters.
0:23 So, let's just look at the scooter one.
0:25 So, just like before, we create a session
0:27 and it does this check, this count
0:29 to see if there are any scooters available.
0:32 If they are, it must have pre-populated it.
0:34 We don't need to worry about it.
0:35 Otherwise, it's going to have some models
0:37 some random VIN values it can use
0:40 and get all the locations
0:42 so that it can then use those to populate with.
0:45 Then we're going to go and add 20 scooters here, 21 scooters.
0:50 And it just randomly fills out the values
0:52 randomly generates a VIN number, randomly picks a location
0:54 and adds it and then commit to all those.
0:56 Same for all the others.
0:58 Right here you can see it's going to get
1:01 the default user as well
1:03 and create a second user so we have more than one.
1:05 I'm going to just delete this one more time so we start over.
1:09 Now let's go to our program.
1:11 And notice this part was still missing.
1:13 So, we'll say import data
1:17 import if empty, and we delete this.
1:19 Okay, so everything should be up and running.
1:22 Let's try to run this and see if we now have data.
1:26 It didn't crash, so that's quite exciting.
1:28 So, here you can see we have our scooters.
1:30 They all got created with their IDs and their VIN numbers
1:32 and their versions, and their various battery levels.
1:35 Some of them are checked out for rental
1:37 because you can see their locations are null.
1:41 These, the ones that have locations, they are checked in.
1:43 Their batteries are charged up
1:45 and they're waiting to be rented.
1:47 Looks like that's working.
1:48 And it turns out the other ones are all good as well.
1:50 So the final thing to do before our app is entirely done is
1:54 just implement these little functions.
1:57 That might sound hard, but it actually is pretty easy
1:59 because we already wrote the data access stuff.
2:02 We just have to do the reporting.