AUTOMATE YOUR LIFE USING PYTHON - 3 Beginner Projects (tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome back I hope you're doing amazing on this wonderful day today we have yet another python automation deck most python tutorials that you see online will start off with oh let's call up a Tic Tac Toe up the thing with those programs is that while they might be good for learning they're not that interesting and as I always say in pretty much every single video on the channel the main part about actually learning the code is being excited about learning to code and one of the best ways to be excited about coding is actually coding up things that are interesting and exciting and most people understandably think that in order to code interesting things you have to be really Advanced but what I want to show with the series is that that's definitely not the case so in this video I'm going to be showing you three python projects that are number one very quick to build number two do not require a lot of knowledge beyond the basics of python and number three that are actually interesting something that you might actually want to use for something and on top of all that number four there are still very instructive and will allow you to learn something interesting and something important about working with python and about programming in general so I hope that these three projects will be interesting to you if they are as always I would appreciate a like down below in the description it helps this video get shown to more people on YouTube so that more people can be introduced into the amazing world of programming and to show my appreciation I wanted to share this picture of a very cute kitten for you to enjoy but now let's move on some python right after we first hear a word from our sponsor so on this channel we always talk about the importance of having in-demand skills like coding to boost your career one of the other most important tools that you need in your skill Arsenal is the ability to communicate ideas by a video so before we move on I quickly want to share an excellent tool for you to do that the wondershare demo Creator I want to share demo Creator allows you to take your idea sharing to the next level let me show you all you have to do is download the app and click record then you can easily record your presentation and your screen at the same time after which we can enter a video editor window where you can add all sorts of cool effects and transitions in addition you can also use democrator as a standalone video editor and they have tons of ready to use templates to get you started with absolutely zero experience you can create yourself a virtual Avatar where demo Creator uses machine learning to create a virtual character that tracks your eyes and your movement and another really important part about video is of course sound and for that demo Creator comes with a built-in sfx library and even a voice changer to give you some motivation if you download the app today and share a video using the hashtag present with demo Creator you'll have a chance to be one of three winners to receive a premium create your license or receive a hundred dollar amazon gift card so if you want an easy way to start creating engaging videos today you can check out demo Creator from the first link in the description thank you for want to share demo creator for sponsoring this video and making these videos possible so let's get into our first python project so if you want to learn the code you're probably someone who's quite motivated and you generally want to be on top of things so you probably want to follow the news right about because coding takes so much time you might not have the time to always open up the five different new sources that you use to get your news and read all the main headlines so that is why with our first project we are building a news automator there is this really cool API called news API and what I'm talking about is this one right here you're gonna click on this button here get API key then you're going to go to your code file up top you're going to create a variable like this we use API underscore key equal so then you're gonna paste basically the key that you get from your API I've got my actual API key just above here but I'm not going to show it to you because it's private then we're going to start defining some functions first of all we want to create this object of query parameters if you send a network request to this URL right here it's going to call the API and based on the parameters that you give it it's going to send you some response and to show you what that means is if you go to the documentation of the news API to get top articles to send a request to this URL right here which we have already defined up here for example for Country we can just Define it in our object as country colon and then there's a list of all options and then for category for example here we can see that the category can be one of either business entertainment general or basically one of these and then the different ones that you can set like for example uh keyword to search the news articles for so once we set the parameters that we actually want so for this first one we're just going to define a function to search and used by category we're going to Define this other function that we're going to pass these parameters to and here the way we actually make a network request do this API using python is using these requests Library so we go requests dot get with the parameters that we just defined and part of the function example response that you're going to get that's going to be sent to your code is going to be something like this and the way we actually access that with our code by calling response dot Json and then we are essentially going to have this object for us to manipulate and if you just look at it we can see that we need to find the Articles key which is then going to give us a list of all the articles with all these fields in regular defined an empty array of results and for article in article so it's going to be a followed Loops of all the Articles we're going to append an object to this results array that has the title which we're going to get with the title key from the art object and the URL field and the way I know that this is how it's formatted is again just by looking at this example response we can see that for every article object we have a title we have an author we have a source and then at the end for all of the results we are going to print a title and the URL as well as a new line and to see how that works I've put this python script inside of my path in such a way that all I have to do is run my terminal window I'm going to just go news and then the name of the category which is business for example and then it's going to print the top business articles from all the new sources for the countries I have chosen which is the UK and the way I did this is by going into my finder going into your root folder and then to get hidden files to show up you have to go I believe it's command shift and period and you should find a file called dot Z profile if you're on a Mac and in here you're going to Define alias and whatever you want to call the program I'm going to go for example news equals Python and then the path to the actual script and then what that is going to do is whenever on the terminal window you type news it is going to be aliased to this command so essentially it's instead of running news it's going to run whatever you defined here so Python and then the script if that makes sense and then if we look back at our script the way I've defined it is the org V1 which you import from sys Arc V1 is going to get the first command line argument you can obviously do whatever you want with this that's just how I've defined it for myself and you probably thought I've defined some other functions as well for example I've defined this function that instead of getting articles by category it gets in my query and again I just looked at the API documentation Hue colon the query string that we want to search for and then if we run that function right here for example comment this out for a minute is now going to get me articles from the UK that match the keyword of Liz truss who is the current prime minister of the UK who's doing a very terrible job this is just some examples of how you might use this particular API you can Define all sorts of functions for example to search for articles by country ton of different things you can do to automate news for you without I think that's pretty cool and something that I actually might see myself using from now on with that let's move on to the next script which is probably the coolest python script that I have made so far honestly and I'm so excited to share this what we're talking about here is a eBay price tracker essentially let's say you want to buy something on eBay for example I want to buy an M1 MacBook Air I'm just looking to buy one used right it can be difficult to tell what is a good price to pay for a used item because as you can see there's all sorts of different prices that this M1 Max books are being listed for and obviously to actually figure it out you would need to do something like come here a couple of times look at all the different prices and sort of take an average and then once you see something that's below the average that's when you know that is a good deal but actually doing something like this manually can take a while so why don't we make a python script that doesn't or for you using something called Web scraping a web page like this it sort of has a couple of different things going on at the end of the day a lot of these things that you see over here like the way they're laid out the way they look all these images all of this is like just styling but behind the scenes if you look at the source of a webpage all we really have here in terms of the contents or the content that we actually care about is a nested list of HTML like different HTML elements all with different information in them we can use Python to essentially load up this information without the styling because the python code doesn't care about what the web page looks like and then search for things using these tags that we can see here and the way we do that is we need to install something called Beautiful soon and then you also want to install and import these other packages just in a moment we'll see what we actually use it for then you're going to go on eBay and I'm on the eBay UK side because I'm in the UK but whatever Countryside you use you're going to go there you're going to search for whatever you actually want to track the price off then you're gonna copy the link up here and you're gonna paste it as a link variable right here then we're going to define a function this is going to take a link and at the end here we run it with the link that we defined we send a get request to get this page using our python code then in order to actually look at it we are going to use beautiful soup so we're gonna go page underscore pause equals beautiful soup with r dot text as a first variable and then HTML parser as the second parameter and just right here if you just quickly print this page part just to see what's actually going on here when you strip out all the styling all the JavaScript all of that this is actually what this web page is like if you just care about the content like the actual information this is obviously a lot to look at or instead want to do is go to the actual eBay page and what we're looking for here all of these search items in this UL so unordered list and all of them have this list object that have a class of s Dash item so what we can do with beautiful soup server variable called search results by going paste pause don't find and we're going to find a UL that has a class of SRP results and from that UL we want to find all items that are inside An Li tag that have a class of s Dash item so essentially this is going to create a list of all of these list items that have all of our search that we want to look at then we're going to Define an empty array of item prices and for all of these search results we are going to then find the actual price and again we just look at the page element in here go on top of the price and see that it is indeed inside a span that has a class of s Dash item underscore price and to actually get this from over here from all of these we would look for a span that has a cost of s Dash item underscore price and to get it as text we go dot text and then sometimes in this search result I'm actually see okay I don't think we have that now but basically I just found when I was trying this that sometimes we would get like price to some other price just to avoid that we go if two is in bad price tags we just ignore it basically but if it's not get the actual price because right now we're just literally gonna get a string with this pound sign and then if it's more than a thousand it's gonna have a comment just to make sure that we're only getting the number price as tag so from item index 1 to ignore the pound sign and we replace a comma with nothing in case it's more than a thousand and it has a comma so essentially that's just policy as a number and then we return them so if you just do that it's all already going to work there's a couple of other things I did after this which we can look at if we just want this right now and we print them and would you look at that we have a list of the prices of all of the MacBooks in our search result right here but we're not done yet just to remove some outliers basically I've created this function here which is going to use numpy to essentially edit our list of prices in such a way that if the price is either two standard deviations below or two standard deviations above the mean of our prices then we're going to ignore it and the last thing we're actually doing first of all defining a separate function to get the average if you want and we can even print that here but to actually make this project as useful as possible it might be worth actually tracking the price over a couple of different days and then sort of getting the average of those to do that we're going to Define this very loss function over here which basically just saves all of these prices in a CSV file with the date and again the specifics of this function here don't matter that much you can literally just copy this I I don't care basically creates this prices dot CSV file which is going to have a field for the date and then the average price and again this is literally a program that I probably will be using going forward so on to the last one we're going to be making a python voice recognition bot exciting times and the way we do that first of all we need to pip install speech recognition I've just got this random text file over here hello world this is a test file for my python screen I'm gonna go test file name equals the file name of the audio file I think it needs to be in this format or I think MP4 works as well then we're going to go R equals Sr don't recognize I was going to initialize an instance of a class that can recognize speech we're going to Define this function over here which is going to take a file name and the first one is very easy all we have to do is with sr.audio file taking the file name as Source we go audio underscore data equals r dot record which is going to record the audio from the audio file in to this variable then we transcribe it into text by going r dot recognize underscore Google which is going to use like the Google speech recognition API software something like that taking in the audio data that we just saved up above and then return the test so if we print that would you look at that if that's magical to you go hit the like button to make this even better we want to be able to record our voice from our microphone and immediately transcribe into texting so this is actually slightly more complicated but not that complicated Go Peep install sound device we're also going to import these two things right here and we find this other function basically here you might need to do some tweaking because this is going to slightly depend on your audio device basically you're going to Define a variable called sample rate which for most devices I believe it's going to be 44 100 duration is gonna tell your program how many seconds to record audio for then we go to audio recording equals SD dot Rec duration time or sample rate sample rate equals sample rate channels equals for me it's one some for some devices it's two again I'm not an audio expert this just sort of depends on your audio device and then D type somebody called int32 and print recording audio SD dot weight which gonna wait for you to record audio actually let me just run this to just to show you actually what it is doing here it's going to start recording right now this is now being recorded by my microphone it's going to do it for five seconds but to do actually what we want to do what we then want to do is write this into a text file and very simply to do that we just go wab dot right when I Define a name for the file that we want to write and this is one of these other variables that we've got saved up here we're gonna say we have a recording dot w a b with example rate and audio recordings or the data that we just recorded this is going to store it into a WAV so a sound file so not quite what we want here but essentially once you run this you're going to get this file to pop up right here with the name that you just defined above and then what we want to do is pause this file in it to yet another function so we're gonna go save text to file and we're going to take the new file name of the file that we want to save our text to which again we're gonna go up here and say the third file name variable for me underscore voice Aztec Dot txt and then all we go with open file name is important that you choose the parameter of w to tell the program that you're going to be writing to the file rather than just reading it as F or file or whatever F dot right and we write the text that we pass in the function into this file and then at the bottom when we run all of these change together what we are doing first we're going to run the function to recognize voice from a microphone which is going to give us this recording sound file over here or it's going to overwrite it if you already have it then we're going to pass that file in to our recognize from file function that is going to return that file as text and we're going to save that as text from voice and then we're going to pass this text from voice in to the save text from file function which is going to say Simply Save this text variable as a file with the file name that we defined above if this chain of events doesn't make sense to you just pause the video I promise you this should make sense and we run it we're going to see some absolute Magic first of all it's going to record this is a recording please subscribe to my channel it's the best YouTube channel ever recording please [Music] be open our voice is texting.tst are you ready for this boom please subscribe to my YouTube channel is okay I messed up the recording a bit but you get the point I hope you enjoyed one of these programs I certainly enjoyed making them I really want to make more of these videos and if you would like me to make even more of these videos the best way for you to indicate to me that you want to see that is by liking the video whatever you want to see just comment down below and here is yet another python automation project idea that I hope you have an amazing rest of your day and I'll see you in the next one bye
Info
Channel: Internet Made Coder
Views: 62,351
Rating: undefined out of 5
Keywords: python automation projects, automate the boring stuff with python, learn python, python automation, automate your life, learn python fast, python fundamentals, bash scripting, learn to code, coding projets, coding project ideas, python tutorial, desktop automation, coding tutorial, python 101, how to automate tasks for beginners
Id: ZRlbf5P2iMA
Channel Id: undefined
Length: 19min 41sec (1181 seconds)
Published: Sat Oct 22 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.