Python Jumpstart by Building 10 Apps Transcripts
Chapter: App 6: LOLCat Factory
Lecture: LOLCat App on Windows

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Finally, let's make sure the cat factory runs on Windows, and this is going to give me a chance to show you one more cool little feature of PyCharm,
0:09 because this is not going to work. So I tried to run my app, is that huh, no module named requests. Of course, that should be a clue to you guys
0:19 that hey maybe this system doesn't have requests installed, so we need to go out to the shell, or out to the console
0:25 and say pip install requests that sort of thing, now you've seen when we were using request but we didn't import at the top
0:32 PyCharm would say hey we will write the import statement for you at the top, but this is cool too, it says hey you are trying to use requests
0:39 we know that this is a module form PyPi form the Python package index and you don't have it installed in your currently selected interpreter,
0:47 but guess what, we'd be happy to do that for you so you can see down here installing packages request, hold on, done,
0:54 so if we try to run this on Windows, you'll see that there is a small problem, it's pretty easily fixed but it's not entirely obvious why.
1:06 So it says it cannot find the specified file, that's weird, and it's talking about start actually,
1:12 we have two ways to fix this, we could say shell=true because apparently the start is just a shell command
1:18 or we could be just more explicit about what we want to start and we could say we'd like to start explorer, let's just go with that to be consistent.
1:30 Beautiful, here are lol cats the ones that you guys are now familiar with, and love so we've been able to use the platform.system
1:38 to figure out the right command for each operating system and we have used xdg open for Linux, Explorer for Windows and open for OS X
1:49 it's not the cleanest way to work in the world but when you are doing this cross platform stuff you know,
1:55 sometimes you just got to put an if statement somewhere but it does list right app that run everywhere and that's pretty cool.
2:02 Let's do a quick review before we move on. So we started out printing the header, this you guys have it downcold, and then we worked with OS path
2:10 to create check for and create our output folder and then we downloaded the cats. If we go down here remember we did a forin loop over the range of 128
2:21 so that let us create our 8 cats and then we just called into our cat service.get_cat() module which we wrote over here, we can check that out,
2:30 and we just went and downloaded the data using requests made sure to set string=true return the raw response
2:35 and then use the shell util copy file object right from one stream, to the other stream.
2:43 Then finally, we displayed the cats using the sub-process module and various operating system dependent apps
2:50 that know how to somewhat display pictures to the user. Now we have our very own working lol cat factory.

Talk Python's Mastodon Michael Kennedy's Mastodon