3 PYTHON AUTOMATION PROJECTS FOR BEGINNERS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome back in this video we're gonna be building three very simple python projects that you can go build right now right after watching this video and the best thing about these particular projects is that they're not some tic-tac-toe or some useless wank like that these projects are actually gonna be interesting and useful what gets me excited is actually building something that i might use myself that's gonna have some practical use for me so that is why i have chosen these particular projects and also in this video you're not only going to learn how to do these projects and also get access to my source code down below in the description but if you watch till the end i'm also going to teach you the basics of shell scripting and how you can use it to run these programs in just a couple of clicks directly from your terminal window my real goal with this video is to show you just how versatile python is and just how much you can do with very few lines of code and that is why python is my favorite beginner friendly language because you can just do so much with it which will keep you motivated to keep learning but let's get started the first project we're going to be building is an image editor now you might think that in order to edit great looking photos you need something like photoshop think again because all you actually need is python let me show you how this is really great library in python it is this one and i'll leave the documentation down below in the description so you can like figure out what else to do besides the things that i'm going to teach you how to do essentially the way you install it is with this command and we're just going to copy that and i already have it installed so it's not going to like do it for me but essentially that is how you install it i'm going to start with some imports then we're going to define a folder to which we're going to add some photos that we want to edit and we're also going to define a folder where we want the edited photos to go once they are edited i'm going to define these as variables just like that so let's say i have some sexy images of myself which i want to edit to look at me better essentially if i want to make a new instagram post out of these i might want to edit them a bit usually i would do this in like photoshop if you're using python it's going to be much easier and much faster as you will see and now to access all of these photos the magic of python is that you can apply all of the same edits to all of the photos in this folder automatically and to do that we're going to apply some magic just kidding just some python code for fill name in os dot list with pass so essentially all this piece of code does is access all of these files all these images in this folder and i'll apply all the code which we're gonna write to it first to open this image using this library we're gonna go image dot open and we're gonna do this this is an f string to make sure we accidentally file you just copy this exact one essentially now this variable holds this image object which is going to allow us to do some edits to it for example what we can do is sharpening we're going to go edit equals image dot and i need to filter and inside we're going to go image filter dot sharp and we need to do a bit of trickery essentially we need to clean out the name edit dot save and i had this saved and i'm gonna do like that and essentially this thing is going to apply some edits to all of these photos and save the edited images in this edit the name folder you ready we've got python 3 go to editor.pi and now we have sharpened versions of these images it's really not very clear and for some reason he rotates them to the left so actually what we need to do is to this one we need to do dot i believe it's convert and a capital l inside i don't just know this by heart i've learned this by looking at the documentation and the things that i'm doing here are just examples that you can do by going into the documentation you can find a bunch of other types of edits that you might want to do this is just example so if you do that well actually no i forgot to convert to l is actually the way you convert it to grayscale actually kind of like that so we'll leave that the way you did rotation was by doing well rotate not convert and we're gonna go i believe you do minus 90 in this instance and now they are the right way around and they are also black and white then you could obviously do a lot of other things what i like to do to my images is increase the contrast you would do is define a factor to be 1.5 for example answer equals image enhance dot contrast which creates this object again with like contrast editing capabilities or something like that and inside we put edit and now we have this enhancer object and this we're going to go edit equals enhancer dot enhance with this factor that we defined and now this new image should have some more contrast we're going to see if this works if you open these you can see that these are a lot more contrasty and basically what you could do if these are the exact edits that you would want to do to all of your photos which you're posting on instagram for example what you can just do is copy them to this one folder just run this program and automatically everything is going to be applied you don't need to like manually edit every photo anymore ever again pretty cool let's move on to the next project this next one is a youtube video downloader now let's say you're going on a trip for example you're going on a road trip or you're going on a flight where you're not going to have access to internet yet you still want to be able to watch internet make coder videos while you're on your trip or maybe some other youtubers i guess how do you solve this problem well what you could do is sign up to youtube premium and pay youtube like i don't know what is like 10 a month to be able to download videos to your computer or you can code like 15 lines of python code and simply download all the videos that you want to download to your computer for completely free and i'm going to show you how to do that what we're going to do is again we're going to be using a python library the library we're going to be using here is called pi tube we're going to copy install pi tube like this i already have it and from pytube we're going to import youtube i believe it's actually youtube like that then we're gonna go from sis impor org b so the way i want to be able to run this program is just from the command line i want to be able to run this program name as well as the link to the youtube video which i want to download the way we're going to be able to access the link from the command line in a python code using this ogb built in library what this means is that essentially arc b takes all of the things that you input into the command line when you're running this program essentially the first argument is always going to be the program name so that's why we don't want to access this one because this would just output the name of this program rgb1 is going to be the first command line argument which we give when we're on this program so that is how we're going to be able to access it and then we're going to need to create this youtube object from yt equals youtube i believe i need to put this link inside of it so it's going to be create this youtube object from this link basically first let's just try to print some information about this youtube video which you want to downl dot title like this like this right yeah and then we might also want to print the number of views that that video has right now views colon and the way we access that is just quite the dot views i believe yep seems to work and let's just see what happens so we're going to go python 3 yt downloader and i believe i need to put this in quotation marks like this and just like that it works it shows title of the video as well as the current views of that video pretty cool okay so now if you want to download this video what do we actually do well it's very simple it's actually only two lines of code let's say we're gonna just define a variable called y d equal to yt dot streams to get highest resolution essentially what this does is because there's obviously multiple different streams of the video that you can download you can download the 4k version or you can download the 360p version if you've got potato internet essentially this function here ensures that it's going to download the highest version of the video possible so in this case i believe there's a 4k version there should be a 4k version available of that video and then we just go yd dot download and then we need to input the folder to which we want to download this video usually use this program myself when i'm editing these youtube videos and i want to include some clips from either my own youtube videos or some other youtube videos i usually like to put them inside this kind of folder right here and you're obviously just gonna input whatever folder you want your videos to go to and then we're gonna see if this works it's gonna download and you see that it's sort of waiting it's waiting for the video to download and looks like nothing went wrong now we're gonna go into this folder my computer right here it's right here youtube downloads and would you look at that it's right there this video is now downloaded into my computer pretty cool again let's move on to the next one by the way at this point if you're finding this video useful a like on this video down below in the description would be highly helpful because it shows youtube that this video is actually half decent and it actually makes the youtube algorithm show this video to more people so if you could just take two seconds to go down there and like the video i would be highly appreciative of that and as a reward for doing that here's a picture of a cute cat okay now the last project which is also very exciting what we're going to be doing is a simple pdf merger so for example when i was in university a lot of the times i needed to combine multiple pdfs into a single file and the way i would do it is that there's a lot of these web-based pdf merges where i need to upload my pdfs into this website and it will like take some time to like merge them and then output this new file but now whenever i need to do it i just use my own python script which took me like five minutes to code and it's much much easier especially when at the end of the video i show how to actually run all of these just from your terminal window using shell scripting but first let's code this up in python what we're gonna need to install here is another library this time it's called i believe it's pi pi pdf two that's the one and we're gonna import it from import pi pdf two then we're gonna import sis and let's start coding now over here i've got these two pretty disgusting looking pdfs from my university days oh god i'm so glad i never have to read stuff like this again but essentially let's say i'm still an economic student at university i need to combine these two files into one file to upload it as an assignment or whatever for file in os lister and we're going to import os as well and the way we're going to access the current directory is by going os like this and we're going to print file to see that it's working actually not like this obviously like this and then obviously we need to check that the file is actually a pdf so that if file ends with dot pdf then we want to access the file and do some magic to it and just like that we can see that it is indeed working and now we can just merge them essentially the way we do it is we create this merger object by going pybdf2 dot pdf file merger right there and inside we don't need to put anything this creates this merger object which we can now do some magic to to merge these files and all we do is two lines of code we go merger append file not style file just like that and then we need to write these in to one combined file that actually saves it as we go merger i believe it's bright and we just need to give it a name and the name we're going to give it to is com bind bsuni docs dot pdf do like this and let's see if this works let's see if i made any mistakes i made mistakes let's see what mistakes i made yeah we want to define this before we do any of this other stuff we're going to define this object right here up here okay it does look like it worked and yeah again i will leave the documentation do this library in the description if you want to do other stuff with pdfs but this is just a very basic it's exactly it's 10 lines of code and you can just do the same thing and that would have taken at least a couple of minutes before pretty amazing now what i'm going to show you is how you can make this even faster so normally to run the script you need to go to your terminal window and then cd into the appropriate folder where all of these programs reside which would take some time obviously if you want to run this multiple times but what you can do instead is code something called a shell script which you can just basically run from this command line window which opens up every time you open your terminal window essentially for example for my youtube things i can just go tsh youtube dot sh and then give the link and it's just gonna download it and the way you do that is pretty easy you're gonna create a new dot sh file which is basically a file which you can run using your shell script directly from your commander you just do exactly what i do we're gonna do is go nano which is this command line base text editor and it's going to give it a name yt dot sh and the sh ending is really important here we go enter to create this file basically here all you do is your cd and then you copy the folder where your file resides the way you get these is you go to where you would normally run your python code in your wd which stands for present working directory and you get the present work interactively you copy it so basically what we're doing is once this file runs the first thing it's going to do is going to cd so change into the correct directory and then it's simply going to run the files we're going to go python three and actually i almost regard a very important part and the start of these shell files where you need to always include is this line which is like hashtag exclamation mark slash pin slash sh this essentially tells the program what version of the shell or what program it needs to use to run this basically you don't need to know any dutch just include this line at the top of all your shell scripts then you do this and you remember how for the youtube program we needed a command line arguments the the program you to access the link of your youtube video as a command line argument the way we do the same thing as a shell script is much easier you just go dollar sign one essentially that's all you need to do what this is going to do is once you input a command line argument on your terminal window it's going to access it using this dollar sign one thing and it's gonna know that that is actually the link that it needs to then feed into your python program which will then do all the magic which we did before we go and save this we go control x it's gonna ask you if you wanna save you're gonna y enter then now this is where the real magic happens you go gsh the name of our file oit dot sh quotation marks link quotation mark boom it shows the title it shows the view it's downloading it let's see if it works we go in that folder and would you look at that it's right there pretty magical and basically you're gonna do this exact same thing for all your other files as well you could go nano.pdf.sh you're just gonna go and basically do the same things and i'll leave that to you as an exercise to do i hope you find this video helpful if you want to access the code that i use you can go down below in the description you're gonna find it on my github but what i would obviously encourage you to do is use this as inspiration slash a starting point and then based on your own needs just go down to the documentation for all these libraries to build the exact kind of either photo editor pdf editor or whatever that you need that you want because that is the most exciting thing about coding is building projects building things that you actually want to use maybe you don't even find these particular things useful but just the mindset of looking for problems to solve and looking for libraries that might already have solved these problems if you do that you will be surprised how many things you can actually do with python with very little code if you want to learn about even more exciting python projects i made this video about how i am automating my file management on my computer using a simple python program so if you want to learn how to do that go watch that video right after this one [Music]
Info
Channel: Internet Made Coder
Views: 865,617
Rating: undefined out of 5
Keywords:
Id: vEQ8CXFWLZU
Channel Id: undefined
Length: 17min 0sec (1020 seconds)
Published: Tue Jul 12 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.