Six Quick Python Projects
Key Takeaways
Builds six quick Python projects including web scraping and QR code encoding with freeCodeCamp
Full Transcript
hey guys welcome to this video in this tutorial we're going to be building six different python projects so these projects are going to be a little bit above the beginners level so you can consider them as intermediate python project so right here i have the list of projects which we're going to be building so as you can see there are six projects right here that we're going to be building in this tutorial so guys if you like more tutorial like this don't forget to check out my channel at code with tomi where i teach more on python so having that said let's dive straight into this video hey guys welcome to this tutorial so in this tutorial we're going to be using web scraping to get the image link of the profile image of a particular github account or let's say github user so what is our program is going to be doing is that it's going to ask a user to input the username of a particular github account and then it's going to return back to that same user the image link to the profile image of that account in which the user input so let's visualize this right here i have my own github account so this right here is my username where you see tomitoko or you can also come to the url yeah you can see that's my username so this is what we're expecting from a user so once a user inputs this username what it's going to get is a link to this profile image so as user clicks on that link it takes the user automatically to the profile image so let me show you an output of what we're going to be building right here you see it says impulse github user i'm just going to import tummy tucker now you can see it gives me this link now once i click on this link i need to open link you can see it takes me to the profile image of that github account now we can do this for various things we can let's say once a user gives us the username we can tell the user how many followers that particularizer have or we can tell the user the amount of repositories or the the twitter and anything anything actually we can do with web scraping so this is a little bit above the basics of python that's why i decided to teach this in this video so on web scripting before we start web scraping we need two things which are requests and ps4 now these things are python libraries these are the most popular python libraries used in web scraping they make web scripting a lot easier to implement in whatever you are building so as you as i said there are python libraries when we want to use a python library that is not built in with python we need to install it using pip or manually install it or however you install your libraries for this video i'm going to use pip to install requests and ps4 now to do this i'm going to say peep install requests now this is going to return to my requirement already satisfied as you can see it says requirement already satisfied that's because i already have it installed and the next thing i want to install is peep install bs4 now this command line is also gonna install this ps4 now this bs4 is uh let me say is a library but what we need mainly from this bs4 is beautiful soup for a beautiful soup only so now let me just close this terminal we have these two libraries installed now what do we want to do we want to start coding now we want to use these libraries in this code so the first thing we need to do is to import those libraries so i'm going to say import requests and then the next thing i'm going to do is to save from bs4 which we installed i want to import beautiful soup but as you can see this beautiful song is kind of long to type most of the times in our code i can just say sbs now what this sbs does is that once we import these beautiful soup function or class or whatever from this library whenever i want to use it in our code we can just simply type bs instead of typing beautiful soup so i'm going to show you how what i mean later in this session so now i've imported that what i just want to do now is to assign a new variable and this variable is what is going to collect the github user so i'm going to say git up underscore user should be equals to input [Music] i'm just going to tell the user to input github user [Music] now once the user input github user let's say my username which is tomitoko is going to be saved in this variable now that we have the github user that design wants to find now web scraping there are some steps you need to do whenever you want to perform web scraping the first thing you need to do is to send a request to that url and as we know the url is going to be this git up url with the username the um whatever user input so we're going to send a request to that page and then we're going to get a response of 200 which means the request was successful now when we send a request to that page what is going to happen is that we're going to get the old html code of that page now once we get the old html code of that page we can easily get any data we are looking for now let's just send a request to that page so let's specify url this url is the page you want to send the request to so as we know it is https [Music] dot com slash now i can just easily say slash tummy tucker but once i say slash tummy tuckle is gonna be giving me only my own profile image but that's not what i want what i want is that it should give me the profile image of whatever our user inputs so now i'm going to make it dynamic by inputting this variable using concatenation so i say https github.com github user which is this variable which is what user input so if the user input any other thing is going to get to that specific url and then get a response now let's send the request so say r equals requests dot get url so now this is gonna send a request to this url which is the url of the user the user input if that makes sense so after getting this the next thing we need to do is to say sub equals to bs now right here normally it was supposed to say equals to beautiful soup or something like that but because we've already imported beautiful soup as bs we can just easily say bs and then our dot content which is this request so we sent a request if we just say r instead of r dot content it's just going to give us the request let's say the response was 200 but the response was 200 means okay but the response was an error or something now if i click here it says r is a response but when i say dot content now this is basically the html source code everything on that page the content on that url so now and then i'm gonna say html dot parser pass it into an html code so now that we have everything all the html on this page we have it saved in this soup variable it's very easy right right what we just need to do is to just basically print or get that specific image and we know this image will be in a tag in an image tag if you're familiar with html you will understand what i mean now i'm just going to say profile underscore image should be equal to soup dot find now here i need to explain a little bit further now soup.find means from this html code we have find a specific tag with a specific class or with a specification or something now when i come back here i'm going to right click on this my image and then i'm going to scroll down to where i see inspect i hit inspect and what do i see i see an html code of this page but because i right click on this image it's going to take me to the html code of that specific image so now i have what i'm looking for i know that it is an um this the url to this my image as you can see this is the url it's in an image tag and the attribute is in an src so it's an image tag it has an out of avatar and then the src is where the image link is being hidden so it's very easy now i know that it's in an img tag right here that's all we know and then let's give it some more information so it knows exactly what we're looking for because this can also be an image tag as it can also be an image um this can also be an image this can be an image anything can be an image if we give it just only this image it's going to give us back all the images we have on that page but what are we looking for we're looking for this profile image so let's give our code some more information so now let's look for under information we can say the image tag which has an out of avatar we know avatar also means your profile image or your display picture or something like that so i'm just gonna say comma curly braces it has an alt that is equals to avatar [Music] now we know what we're looking for so now this particular tag is being placed in this profile image variable if i print this profile image variable i'm going to get the wall of this html tag but as you know that's not what we're looking for what i'm looking for is only this link so what i'm just gonna do give it a little bit of more information after the world code on that line i'm just gonna say get the src attribute which is where the link is src so from that tag gets the src attribute easy and after that i can just print profile image now this is all the code we need to write for this our python program i hope you understood everything we did so let me run it and just let's check it okay let's delete this timing now to make things easier and run again okay good now it tells us to input github user i'm just gonna input my username and then let's wait you can see now that it just prints the image link to this username so once i open this [Music] i open the link now you can see it gives me the link to my profile image which is very good which is what we want so we've accomplished with beauty to this program just let me just quickly have a quick recap of what we did so i said from the beginning we need two libraries for web scripting there also countless libraries we can use for this but this is the easiest to implement and to get started with as a beginner in web scripting so we say import requests which is the first library we need i'll say from bs4 import beautiful soup as bs which i explained why we put as bs which is just to make it smaller to type instead of typing beautiful soup now we added a new variable which was github user and then this github user collected the username of the github profile we want to get the image link of and then we just send we specify the url which is github.com that user and then we sent a request to that url and then once we got the response we use beautiful soup to get the particular html source code after doing that we now go to the profile image so sub dot find image tag alt which is avatar give me the slc which is the source and then once we have that in this profile image we just print it to the user very good very understandable now i hope you got what we did in this tutorial hey guys welcome to this tutorial in this tutorial session we're going to be building a python program that is going to bulk rename all the files in a folder so what we're going to be building is like a bulk renamer python program so this program is going to go into a particular folder on our desktop and then it's going to rename all the files present in that folder to whatever we give it so let me i would have loved to show you the output before we start coding but there is no way to do that without having the code right there already so um let's just go ahead with the coding phase and we'll see the output when we're done so let me just uh go into the folder so right here in this folder i have three images with um different names so the python program is gonna come into this folder and then rename everything to let's say images zero images one this one might be img0 img1 img2 accordingly that's how it's gonna rename so it's a bug renamer uh let me say program let's go ahead and do this so we're just gonna import our os just for python to know the operating system we are using so now that python we've imported os we're going to create a function that is going to rename multiple files because as i said this program is going to rename all the files present in that folder so it might be one it might be two some multiple now we're going to set i equals to zero now as a default it sees that the oh let me say the other files in that folder is zero so that's why it says i e to zero before we do this we first have to have our function so this i should be in our function so this is our function we can name it main that's the main function it doesn't have to take any parameter so now i is equals to zero and then we have to specify the path now this path is the directory in which the folder is so i'm gonna come to this folder right here just something like a bar like a directory bar we're gonna copy it we come back here and paste so right now this is the it's just like a url you know um www.something.com so this is just the local directory where python is going to go find our folder but as you can see um automatically or let me say in default when i copied the directory link or something like that it gives me in front slash so if i when i'm done and i run this while this is team front slash we're going to get a unicode error so we need to change all of these everything like this is in the backslash sorry for that mistake but we need to change all of this to a front slash so like this we need to change everything to a front slash and then the last one to a front slash now python knows where to go get all these files from now i'm just going to use a for loop to loop through the old file so c4 file name in os dot list there of path so it's getting all the files in this part and storing it as a list so now i'm just going to say my underscore dest let's just name it as this variable should be equals to now what do we want to save it as let's just save everything as img something like img0 img1 img2 so cimg plus string [Music] i then plus does jpg we want to save everything as a jpg file we can save it as a png we can save it as tif anything we want but yeah we want to save it as jpg so if you try to get what i just wrote here this is a variable yeah so in this variable well the name is going to be img plus string i so as i said this i it sees the default as zero but since we are looping through everything it's gonna get it from zero one two so it's gonna be img that i for this first one is gonna be zero so it's gonna be img zero dot does jpg so still going to remain the jpg so when we run this you're going to understand the concept i used right here so now we can just simply say my source [Music] should be equals to path plus file name and then let's now see my tests should now be equals to path [Music] close my desk again so right now let's just rename the function with everything we've done we just say os dot rename [Music] my source my dist so now this is just renaming it and then we increase it so we say this i we have to increase it as it's looping through each of it so say i plus equals one or we can just say i equals i plus one or something like that but this is okay so then after doing this you know we need to run this function immediately the python program is being run so say if on the scan name this underscore equals to underscore underscore main on this girl underscore then we put a column and right here we just got our main function now this is good now i'm just going to save this file if i come back here and let me just refresh this same your directory you can see that i still has this name but now when i come to my code and then i run my code now you can see here it gives me an error so what does it say it says file not found system cannot find the file specified so it can find this file exactly um what is it looking for now you can see it's looking for c slash tests img0 so there's a little problem with the link between the path is trying to find a file named path so what we need to do is to make sure that there is no problem right here so let's quickly scroll down a little bit and then right here what we can just do let's just make sure there's no problem [Music] so osd rename my source command my disk now this is just making sure there's no problem and then everything is a string here let's start from here using a for loop for file name in os does lists there so okay now where the problem is coming from is um this let's run it again you see it's going to give us that same error so right here whenever you're using um let me say a directory as i said first of all we need to change it to front slash and then we must make sure that the ending we also add another font slash now when we run this i'm not going to have any errors and everything right here is going to be renamed to img0 imd1 img2 uh no no no no no like that so now let's try to do this we run it it doesn't give us anything right here as you can see but when i come here you see everything has been renamed img0 img1 img2 the jpeg now these is how to basically bulk rename all the files in a particular let me say any particular folder now i can change everything again you know let me just cancel that instead of img i can say image and i can just let me still leave it as jpeg so now i change everything to image i know what i want to do i want to make this more so i'm just going to make it a lot of files so now you can see we have all those files i think we have 13 right here now and then once i just run this first of all you see everything is img0 mg1 and you to copy now this is going to be renamed from this when i run it now just want to make sure that yeah so it's wrong without any error now you see img0 i'm in image0 image 1 2 3 all the way to 12. now that is how to bulk rename using a python program so let's go through what we did in this tutorial so we imported os which is going to allow us to get our operating system if on the windows or on a mac if on the linux or whatever then we just used a function we gave it main and then we said i equals to zero now we said the path should be equals to the directory which we are looking for and then we use the for loop to loop through everything my my desk this my desk so like my destination or something like that the final name which you want to name it we gave it a particular format then we just use all these to make sure we pass it and then we use os.rename to rename it and then after doing for one we increase i by one we look through again all the all files and then we now use this if statement to make sure that immediately we run this program it automatically calls this function and that's what we did in this tutorial session i hope you understood it i hope you guessed the concept of renaming bug files in python hey guys what's up welcome to this tutorial um so in this session we're gonna be building a weather app so this weather program is gonna tell you the current weather situation in a particular city or a particular location or country or town so what we're going to be building is a program that is going to ask a user to input let's say a city or a town or any location and then it's going to return to that user details of the weather situation in that location so let's say for example a user inputs in london it's going to tell the user first of all where london is located and then the current weather situation right there so for us to do this we're going to be using the open maps weather api open weather maps appear so when i come here this is their website openweathermaps.org all you just need to do is to sign up so when you sign up you log in and it comes straight to api keys and you're gonna see that you have this default key so once you have the default key we're gonna copy it and then use it in our code later but for now let's start with the code just make sure you have the api key first of all then you can follow along so now what we just need to do is to import requests [Music] now on this request is a python libraries for sending requests to any website so you know we are using the api of this website you have to use requests to send a request to that website and if you don't have this just install it by saying pip install requests in your terminal so now we're also going to import something named pretty print from b print import b print so when we send a request to this page is going to give us a response in a json format so when we have that response in the json format is always not so easy to visualize or to read so this pretty print library is going to turn that json format into like a tree you know a what tree or dictionary tree in which you are going to be able to read normally so after that what we just need to do is to specify a new variable and name it api key so something like this let's leave it blank for now and then let's add a new variable and name is city so this will be an input from the user and then we're going to tell the user to enter a city so now once we have whatever the user inputs let's just say base url which is the url we're going to send the response to then we're going to do i'm going to paste this so this is the url which we're going to send the response to but whenever we're sending this response to this url we need to send it with our api key and we also need to send the response with the city we want to get a response from so i send a request to this url with our api key and the city then we're going to get a response so i'm just gonna say plus the api key so before plus api key this is the normal url then let's add a parameter by using these and i'll say app id is equals to api key like this so i just concatenating and making it a perfect url so now let's continue with the concatenation by saying plus and then let's say and q which is a query or search or something like that then it's now the city so whatever the user input now let's say whether i underscore data because requests dot get right here let's make sure we're using the right thing request dot get base url dot json so now request the get base url.json as i said we're going to get a response from that url and it's going to have to be in a json format so now we have everything we need about this current city in a json format but let's use pretty print to make sure that it is readable and it makes sense so say p print weather data so this is going to pretty print the weather data now let's run this program right here it says i should enter a city i enter london now you can see it says invalid api and why is that because right here in the code let me quit this i said we should leave the api blank for now so let me go there and copy my api this is my api key and paste it there so remember i said we need this api key so that's why you have to come here create an account log in come here to api keys and then get your api now when we run this we won't get any error and then let's say london now you can see that it gives me information about the weather situation in london so right here entire city london base station so cloud oh it's giving me all this the coordinates um latitude and the longitude is giving me all this so right yeah it feels like 273 points it's 3d humidity the pressure the temperature the temperature marks are minimum the name the country the id the sunrise the sunset the type the time zone the weather um description the weather is missed and mainly missed so the wind is 60 and the speed is 4.12 so it's giving me all this information which i need so this is how to use open weather maps api to get the current weather situation in any city in the world now we can try this for other cities now let me just run this program again so [Music] entire city let me enter a city like um delhi i entered delhi in india now i have this and it also gives me everything i need to know about delhi as you can see it says it's from india so this is basically how to use this open media webs api get it in a json format pretty print it and then you can implement it let's say you're building a web application a gui our mobile app anything you're doing you can use this python program to implement it in your application now let's go over what we did this is pretty simple we just imported requests we imported printer print we got our api key from here we use the city variable as an input we make sure we specify the url then whether data we sent a request to that url and then we got a response and stored our response in weather data and then we just pretty printed it that was simply all we did now that's going to be all for the weather with python hey guys in this tutorial we're going to be building a countdown timer program using python now this program is not to or this project is not too advanced is a little above the basics the reason why i'm just teaching this is just to show you how to use the while loop concept in some more advanced projects in python so uh we're going to use while loop to do this and then we're also going to use a python library called time so before we go into coding let me show you the output or the final product of what we are going to be building so you can see here it says enter the time in seconds so this our program is going to ask a user for the amount of seconds it wants to count down to if it's 10 seconds if it's just one second if it's five seconds it's gonna count from five four three to one a normal countdown and then after that it's gonna print a message let's say like countdown done or go for a run or something like that so let me show you how this works so now i say three seconds i hit enter it says three two one and it says go for a run now now i can print any message there i can say i can make let's just say countdown done or throw up the fireworks now or something like that so this is how to build a basic uh countdown timer is in python let's get straight into it so now i'm just gonna quit this terminal and the first thing i need to do as i said i'm gonna be importing time time is a python library used whenever we're dealing with time obviously so say import time now after importing time i'm going to create a new function and i'm going to name it countdown this function is going to be what's going to be handling everything concerning the countdown so i'm just gonna say def counts down and i want this function to take in a parameter called t now this t should be the amount of seconds in which a user wants to count down to so we'll put in our column and then we'll say while c [Music] and then we're just going to say minus comma section sscs should be equals to divm od now i usually call this div mode or i don't know i just say div mod and i put t in a matter of 60 seconds so this is the second is telling you why isn't the seconds to count down and now say timer should be equals to our code then we'll put curly braces and then 0 to d and then what i need to do now is to pull a column after this another color braces and then i'm just going to say 0 to d again and then after this i'm going to say dot format [Music] minutes comma seconds and then what i don't want to do is you just print timer [Music] and then end should be equals to [Music] backslash r now this is just the format of the syntax of the way we build this project now i can say time dot sleep and i can give it one so after one it should be done then t minus equals one then after this timer is done i can just say print [Music] timer completed or something else [Music] now after this what i just need to do now is to ask the user to input the amount of seconds say t should be equals to inputs and the time in seconds so i want to ask the user for the amount of time and then after i know that i'm just going to call that function our countdown function i'm going to give it the parameter in t i'm giving a parameter of t but making sure that t is first of all an integer before passing it into this function now this is all we need to build this simple program now let's quickly go through everything we just did first of all i imported time which i said is the library which deals with everything about time in python we are working with seconds minutes hours days months years time can do everything if you want to get the current time let's say um the current date and time that from that library can do everything you need well now we are working on accounts down so once we have that time we just defined a new function and named it countdown and we made it to taking a parameter which is t and then yeah it's saying t as a string but we are making sure that whenever we are calling that function we are making using it as an integer just to avoid any errors so now after assigning or defining that function we give it t t is the amount of seconds so say while t this means as long as t is still available then we just want to say means sex equals to div mode t60 which is an integer then timer then we just give it this format then we'll say dot format into minutes and seconds so then we just want to print this timer and end with a backslash r now these are just the parameters or attributes that this time library needs so it's not something you need to let me say put on your head if you just have a notebook or something you can just write it down and then keep using it whenever you need to so now we can say time does sleep once it's done and then time minus equals one so once everything we're done with configuring it counts down we can just simply print timer completed so the function is done we're done with the function then we just add a new variable named t and then we took these out to input the time in seconds so if these are input 60 seconds it's gonna cost us a second is that input 50 it's gonna count 50. then we just call that function once we know what the user wants countdown integer t now we run this when we run these it should ask us for the amount of time we want to count down in seconds so let's wait for this to run this should be up and running within some seconds okay nice so down here okay let me yeah down here it says enter the time in seconds so let me enter eight seconds i hit enter so right here it says key error which is o zero to d now if we come back up here it says there's an error line 15 when calling that function and then on line six so the error is actually coming from here now the reason why there's an error is simply because we didn't add a column between 0 to d so this is the format of time when we're dealing with this time library we need to do everything in the right syntax so whenever you are using 0 to d the first one represents the minute the second represent the seconds so you must make sure to also add this column now this was the reason we are getting this error let's quit this time you know and run it again now we shouldn't be having any errors this time around now you can see it says enter the time in seconds we say 8 and then now it starts counting 6 5 4 3 2 1. it says time completed now this is how to build a countdown timer using while loop in python hey guys so in this tutorial session we're going to be building a password generator program so this um python program is just going to generate a very strong password for a user now let's say user comes to this our program and then he's gonna like put in the amount of password he wants to generate and then it's gonna generate let's say user puts in nine and then he wants to generate a password with nine characters it's gonna generate nine password with nine characters so let me visualize what we're gonna do so this is the end product of what we want to build now the output you see it says number of passwords now in here if i type seven so that means i want to get seven passwords seven different passwords and it says password length you know different sites let's say you want to create a password for you want to create a new account on a site and then you don't know what password to use so this our program can randomly create a very strong password for a user so now different site has different password characters they need so now let's say this our platform requires a character of seven or let me say eight at least so if i put eight it's gonna generate seven different random passwords with eight characters each when i click enter you see it says here are your passwords as you can see it gives me all these random passwords that are eight characters long now this is what we're going to be doing in this tutorial session now you can see that um this is not too advanced for a python project but it kind of teaches some things you need to know working with python so let's just get into that so let me close up this terminal right here now what i want to do we're going to import a python library called random now this python library we don't need to install it it's built in with python so all i just need to do is to say import random now once i have this imported what i need to do next now i can just print to the user i can do something like this print um password generator [Music] let's say welcome to [Music] to your password generator so now this is just telling the user that um this is a password generator and then the next thing we're going to do is to just simply assign a new variable so it's going to have something like charge now this charge is a string but what is in this string is random characters very very random characters so we're going to have this variable called chars what is going to be in here is letter a to z in small letter letter a to z in capital letters we're also going to have some random symbols and we're also going to have 0 to 9 so we're going to compile all this into one string and then our password generator is just going to randomly pick different characters and mix it up and provide our password so you're going to understand this in a bit let's just continue with what we're doing so this characters let me just paste in what we're going to put so now i pasted this in right here you see it says a b c d e f g h i j k l m n o p q r s t u v w x y z so right here is list from a to z in small letters the same thing it does here a b c all the way to z but now in capital letters and right here you see that we just have some symbols or to this place and from here we have 0 to nine so we just mixed up all these different characters together to so that our password generator program can randomly pick any amount from this long character and give us a strong password strong and unique password to be precise so now that we have that the next thing we need to do is to have a new variable and name it number [Music] now this number is going to be a variable which takes the amount of passwords a user wants to generate let's say a user needs 5 passwords or 6 different passwords now this variable is going to be what is going to tell us how many passwords should we generate so now it's just going to be a simple input [Music] and then i can just simply say input amount of passwords to generate so now this is gonna as i explained earlier tell us the amount of password the user wants to generate and i want to make sure that i convert this to an integer because when i'm using it in my function my function we must see this as an integer so because we want to get the amount of something which is a number so it needs to be an integer if the string is going to trust a type error so let's say integer of number now we have to collect another variable and this one should be length and now this lens should be the length of the password let's say the user wants seven characters or eight characters this variable is going to collect it let me say your password length [Music] sorry about that [Music] so let me just write something like input so this is also another variable telling the user to input the password length and i also want to make sure to make this an integer because as i explained we're getting the amount of something the amount of a particular value so we want to make sure it's an integer so when we're using this in our function it gets it as an integer so now once we have everything we need from the user let's just print to the user here are your passwords so now this is just so in the user here are your passwords so after this we're going to use a for loop to now first of all get all the passwords user needs and then print it to the user so after here are your passwords what should be next is obviously the passwords so now is a very simple for loop very very easy one i'm just going to say for pwd it means password just shutting it to pwd in range and note this pwd can be anything it can be for p it can be for d it can be for passwords and full anything now i just um use that there just to denote password because it makes more sense but that is not a specific um let's say it's not a must that that must be pwd so that's just a basic concept of for loop so for pwd in range of number so we're getting the range of this number variable right here so what i want to do is to set a new variable and name it passwords [Music] so now these passwords we're going to leave it empty for now and then after passwords another for loop so it's like a nested loop we'll say 4 c in range [Music] range of length [Music] now i want to do say password plus say passwords plus equals random dot choice and then we give it this character variable so what this is doing is we are adding random.choice to this password variable we set right here so random the choice is this we imported remember we imported random now this is just a python module or library which gets the random text from a particular string so i say random the choice from this character string which is this so just going to get random characters from this string and then once it has it it's just going to pass it into this variable which we assigned earlier so after doing this now you know what we just want to do just print passwords as easy as that now this is a very easy way to build a simple password generator program using python let's run it and see the output now we run it let me quickly kill this terminal we run this let me increase it so now it says welcome to your password generator it asks for the amount of password to generate let's just generate one and then input your password length we want the amount of characters in the password to be nine now when we hit enter it says here are your passwords now you see it gives me this password if i count it one two three four five six seven eight nine now it gives me this very random and strong password from our program so it's just automatically generating a password now i hope you understood what we did in this video because it's a very cool project which you can implement let's say into your gui application or your web application or anything you're doing so this is just how to generate a random password from or using python so guys in this tutorial session we're going to be talking about encoding and decoding qr code in python so let's first start with encoding qr code what i mean by a coding qr code is just creating a qr code using python that means creating a qr code and then filling in some data with that qr code so when we let that decode that qr code it's going to give us back that data so now whenever i want to create a qr code in python there are various python libraries you can use but for this video we're going to be using qr code library so we can first need to make sure we have qr code installed let's us open up a new terminal and then okay i have an existing terminal so i'm just going to say pip install qr code now this command line is going to install qr code but for me it says requirement already satisfied because i have it installed already so let's just go ahead and close that up right now what we just need to do is to import qr code like this now that we have qr code imported we're going to have a new variable and nami data so this data is gonna be uh let's say whatever that qr code is gonna mean like whatever that qr code what the data are going to encode into that qr code so let's just say the data of this qr code is um [Music] don't forget to subscribe [Music] also we're dealing with python so we can put um [Music] these python we see that we want to close it so we have to put this backslash and then we can now come here and then close it so that's the data we want to include don't forget to subscribe and now let's just encode the data into a new qr code so i'll say make i'll say img should be equals to qrcode.make and then encode it with data so it's going to encode it with this data variable and then once we have that we're just going to save it as an image file so say image dot save [Music] and then we're going to save it come here right here we want to save it in this folder so right here we're just going to copy this particular folder go back and paste it there so i want to save it in this folder and remember that anytime you are working with directories in python you need to change this to a font slash it's always in backslash automatically so we change it to a front slash same thing here we have to change it to a front slash everywhere so now that we have that done so i want to save it to this directory i will name it my qr code dot png so now this is gonna save it as my qr code.png if i come here and refresh here you see that it's empty it's an empty folder i come here and then run these now you see it doesn't give me anything right here but if i come here i now see a new picture named my qr code so yeah as you can see it is a qr code image so that is how to basically create a simple qr code but now let's dive deeper let's say i want to customize our qr code more like i want to give it let's say a red coloring or a particular border size or something like that so we're gonna come back to our code let's close this up and then we're gonna leave the data the same don't forget to subscribe and then what we're just gonna do right here let me just make sure i copy this so i don't need to you know write it again so from here i can delete so we're making our data the same so what we want to do we just want to basically change the color and then change like the size let's say the box size uh the version of the qr code the border and stuff like that so let's create an instance of the qr code class we'll say qr equals to qr code dot q our code and then let's give it a version of one let's say we want the version to be one and then box size let's say box size should be 10 and then border should be like five so now we have that instance then we'll say qr dots add data of data so it's just adding this data to the qr code you want to create with all this information also and then let's say qr dot make feet equals true and then we'll say img should be equal to qr dot make on the skull image feel on the color [Music] should be equals to red and then i want the back color should be equals to white like this so now i've i have everything i want to configure and i'm just gonna say image.save and then we want to save it right here in this directory and let's name it my qr one dot png so we don't have two files colliding so we run this it doesn't do anything in the terminal but when we come here now you see we have a new qr code and if you can check it's a little bit smaller uh this is a little bit bigger i don't want to open the pictures now just to keep the video minimal so as you can see it is red and the other colors are white as we configured so that is um how to basically encode um some data into a qr code and design the qr code however we want it so now we've talked about encoding now let's talk about decoding the qr code now you know that we passing this data which is don't forget to subscribe into our qr code but what if we have this qr code already and then want to get whatever data is inside that qr code now how do we do this let's just delete all this now for us to decode a qr code that means get the data written inside our qr code we need a python library called pyz bar now there are a lot of libraries you can use for this but for this video and the one i use personally that i love is p y z bar so you just need to say pip install pyz bar to install that and then as you can see it tells me requirement already satisfied because i have it so right here i'm just going to say from p y z bar dot p y z bar import decode so i'm going to import the code function and then also want to import pillow so you also need one more python library called pillow so you just need to say pip install pillow so say from pill import image image so the pillow library to install it you say pip install p-i-l-l-o-w but when you are importing we say from pir import image so now what image do we want to get the data of say store it in a variable so we'll say image dot open now we wanted to open let's paste it my qr code.png which is this first one since we wanted to open that it has opened it already and stored it in this img variable so now we just say results there's a new variable named results now we just decode that img which we opened now that we have everything is just printed to the screen so results let's run this you can see decoded data don't forget to subscribe the type is qr code you can also do it for barcode you know different types of codes rx these are just telling us the way it's the position but there's no way i want we just want data don't forget to subscribe now that is how to basically decode a qr code now it's not a mods that is a qr code that you created you can just take a qr code online and use this to decode it you know just for practice purposes yeah so that is all about qr codes and coding and decoding qr code with python so guys that's going to be all for this video i hope you learned something i hope you enjoyed it uh if you have any questions just drop it now in the comments i'll make sure to answer a question having that said thank you so much for watching and bye for now
Original Description
Improve your Python programming skills by coding six different Python projects. You will create a web scraping program, a bulk file renamer, a weather program, a countdown timer, a password generator, and a QR code encoder / decoder.
✏️ Course developed by Code With Tomi. Check out his channel: https://www.youtube.com/c/CodeWithTomi
❤️ Try interactive Python courses we love, right in your browser: https://scrimba.com/freeCodeCamp-Python (Made possible by a grant from our friends at Scrimba)
⭐️ Course Contents ⭐️
(00:00) Intro
(00:37) Web Scraping Program
(13:53) Renaming Bulk Files
(24:54) Getting Weather Information
(33:12) Countdown Timer
(42:11) Password Generator
(53:12) QR Code With Python
Connect With Tomi:
🐦 Twitter: https://twitter.com/TomiTokko3
📄 Newsletter: https://www.codewithtomi.ml/p/newsletter.html (and get a python ebook for free)
--
Learn to code for free and get a developer job: https://www.freecodecamp.org
Read hundreds of articles on programming: https://freecodecamp.org/news
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from freeCodeCamp.org · freeCodeCamp.org · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
React: Production Server Setup Part 2 - Live Coding with Jesse
freeCodeCamp.org
cookies vs localStorage vs sessionStorage - Beau teaches JavaScript
freeCodeCamp.org
Browser history tutorial - Beau teaches JavaScript
freeCodeCamp.org
Graph Data Structure Intro (inc. adjacency list, adjacency matrix, incidence matrix)
freeCodeCamp.org
React: Parameterized Routing with Next.js - Live Coding with Jesse
freeCodeCamp.org
React: Dealing with jQuery Issues - Live Coding with Jesse
freeCodeCamp.org
setInterval and setTimeout: timing events - Beau teaches JavaScript
freeCodeCamp.org
Browser and Device Testing - Live Coding with Jesse
freeCodeCamp.org
Last Minute Updates - Live Coding with Jesse
freeCodeCamp.org
Post Launch Updates - Live Coding with Jesse
freeCodeCamp.org
React: Setting Up Google Analytics - Live Coding with Jesse
freeCodeCamp.org
React: Masonry Layout - Live Coding with Jesse
freeCodeCamp.org
Load Balancing Digital Ocean Droplets - Live Coding with Jesse
freeCodeCamp.org
try, catch, finally, throw - error handling in JavaScript
freeCodeCamp.org
Load Balancing: SSL Passthrough Setup - Live Coding with Jesse
freeCodeCamp.org
Graphs: breadth-first search - Beau teaches JavaScript
freeCodeCamp.org
React: Masonry Layout Part 2 - Live Coding with Jesse
freeCodeCamp.org
React: WordPress API Live Search - Live Coding with Jesse
freeCodeCamp.org
Creating WordPress Custom Post Types - Live Coding With Jesse
freeCodeCamp.org
Dates - Beau teaches JavaScript
freeCodeCamp.org
Miscellaneous Front End Updates - Live Coding with Jesse
freeCodeCamp.org
Merging a Pull Request from GitHub - Live Coding with Jesse
freeCodeCamp.org
React + Prettier + Standard JS - Live Coding with Jesse
freeCodeCamp.org
React: Sortable Responsive Table - Live Coding with Jesse
freeCodeCamp.org
Geolocation Sorting by Distance - Live Coding with Jesse
freeCodeCamp.org
Tradeoff Matrix - Agile Software Development
freeCodeCamp.org
The Definition of Ready - Agile Software Development
freeCodeCamp.org
Getting first React job without experience - Ask Preethi
freeCodeCamp.org
React: Google Analytics Click Tracking - Live Coding with Jesse
freeCodeCamp.org
Submitting a PR to an Open Source Project - Live Coding with Jesse
freeCodeCamp.org
Should I go back to school to get CS degree? - Ask Preethi
freeCodeCamp.org
Hero Section CSS Changes - Live Coding with Jesse
freeCodeCamp.org
Working Agreement - Agile Software Development
freeCodeCamp.org
A day at Pennybox with Co-Founder Reji Eapen
freeCodeCamp.org
React: Sorting and Filtering Data - Live Coding with Jesse
freeCodeCamp.org
React: Sorting and Filtering Data Part 2 - Live Coding with Jesse
freeCodeCamp.org
React: Building a New UI - Live Coding with Jesse
freeCodeCamp.org
Definition of Done - Agile Software Development
freeCodeCamp.org
Getting started with jQuery (tutorial) - Beau teaches JavaScript
freeCodeCamp.org
Making a React Blog with WordPress Content - Live Coding with Jesse
freeCodeCamp.org
React, NextJS, CSS - Live Coding with Jesse
freeCodeCamp.org
jQuery events - Beau teaches JavaScript
freeCodeCamp.org
React/NextJS Routing and WordPress API Custom Types - Live Coding with Jesse
freeCodeCamp.org
React: Working with API Data - Live Coding with Jesse
freeCodeCamp.org
React: Refactoring Components - Live Streaming with Jesse
freeCodeCamp.org
jQuery effects - Beau teaches JavaScript
freeCodeCamp.org
More React Refactoring - Live Coding with Jesse
freeCodeCamp.org
animate in jQuery - Beau teaches JavaScript
freeCodeCamp.org
"Finishing" My React Site - Live Coding with Jesse
freeCodeCamp.org
Starting a New React Project (P2D1) - Live Coding with Jesse
freeCodeCamp.org
React Project 2 Day 2: Learning Material UI - Live Coding with Jesse
freeCodeCamp.org
The Agile Manifesto - Agile Software Development
freeCodeCamp.org
jQuery: get and set with http, text, val, and attr - Beau teaches JavaScript
freeCodeCamp.org
React Project 2 Day 3 - Live Coding with Jesse
freeCodeCamp.org
The INVEST approach to product backlog items
freeCodeCamp.org
React Project 2 Day 4 - Live Coding with Jesse
freeCodeCamp.org
Chickens and Pigs - Agile Software Development
freeCodeCamp.org
React Project 2 Day 5 - Live Coding with Jesse
freeCodeCamp.org
jQuery: add and remove DOM elements - Beau teaches JavaScript
freeCodeCamp.org
React Project 2 Day 6 - Live Coding with Jesse
freeCodeCamp.org
More on: AI Pair Programming
View skill →Related Reads
📰
📰
📰
📰
AI Weekly — 2026-06-26 to 2026-07-03 | Curated Surfaces, Sovereign Bets
Dev.to · Yang Goufang
Sora Is Shutting Down: The 6 Best Alternatives in 2026 (Ranked)
Medium · AI
Qualcomm Just Tried to Buy Nvidia’s Biggest Threat. Then Everything Fell Apart.
Medium · Data Science
Would You Take $85,000 From the Company Warning AI Might Take Your Job?
Medium · AI
🎓
Tutor Explanation
DeepCamp AI