#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 but we have no data. We can't really test it. So, let's go and add one more file.
0:08 And this one I'm going to drop in and just talk you through because it's super tedious to write.
0:12 So, what this is going to do is it's going to import data only if those particular tables are empty. So, it's going to import only the user's table
0:22 if there's no users, or the scooters if there's no scooters. So, let's just look at the scooter one. So, just like before, we create a session
0:28 and it does this check, this count to see if there are any scooters available. If they are, it must have pre-populated it.
0:35 We don't need to worry about it. Otherwise, it's going to have some models some random VIN values it can use and get all the locations
0:43 so that it can then use those to populate with. Then we're going to go and add 20 scooters here, 21 scooters. And it just randomly fills out the values
0:53 randomly generates a VIN number, randomly picks a location and adds it and then commit to all those. Same for all the others.
0:59 Right here you can see it's going to get the default user as well and create a second user so we have more than one.
1:06 I'm going to just delete this one more time so we start over. Now let's go to our program. And notice this part was still missing.
1:14 So, we'll say import data import if empty, and we delete this. Okay, so everything should be up and running.
1:23 Let's try to run this and see if we now have data. It didn't crash, so that's quite exciting. So, here you can see we have our scooters.
1:31 They all got created with their IDs and their VIN numbers and their versions, and their various battery levels. Some of them are checked out for rental
1:38 because you can see their locations are null. These, the ones that have locations, they are checked in. Their batteries are charged up
1:46 and they're waiting to be rented. Looks like that's working. And it turns out the other ones are all good as well.
1:51 So the final thing to do before our app is entirely done is just implement these little functions.
1:58 That might sound hard, but it actually is pretty easy because we already wrote the data access stuff. We just have to do the reporting.


Talk Python's Mastodon Michael Kennedy's Mastodon