Awesome Python Automation Ideas

Patrick Loeber · Beginner ·🛠️ AI Tools & Apps ·5y ago

Key Takeaways

Builds a website blocker using Python and Pygame to automate site blocking

Full Transcript

what's going on guys today i show you a couple of awesome python automation tips that you can use every day to simplify your life so let's jump right into it by the way you'll find the code for every project on github so if i go over the code too fast you can head over there and check it out again and if you enjoy this content please hit like and subscribe first we'll have a look at how to automatically send emails with python this is a very simple script that we can use for various use cases and later you see how i utilize the script in two other projects first we import the built-in libraries then we create one function that takes the message as argument then we need to set up the part the server in this case i'm using gmail and the emails and password just a quick note here normally this is going to be your normal gmail account password but if you use two-factor authentication then you need a different password so for this just go to myaccount.google.com security and create an app password alright so now that we have that we're going to set up a connection and then try to log in and send the mail and in case of an exception we just print out an error so now we can use this function in other projects the second idea is to automatically scrape a chalkboard and send us an email when a good-looking job is detected for this we used the site remote ok.io which is a very cool site specialized in remote jobs they provide a free api that returns json data so we're going to send a request to this api endpoint before we write the code i recommend to set up a virtual environment like i do you can skip this part if you don't use a virtual environment but you still need to follow the next installation commands we say pip install requests as we're going to need this module in a second all right now we import requests and also json then we import our helper script from the beginning we specify the url i showed you and the keys we want to inspect then we specify the text that we're interested in for example here we can use python javascript backend mobile or whatever you're interested in then we create a function and send a get request to the url and get the json data from the site we iterate over all the results and take only the specified keys then we get the tags from the tags key and now we want to keep only the jobs that contain at least one of the wanted tags we defined in the beginning so for this we use a nice pythonic solution and convert the list to a set and then call the set.intersection method and if this is true it means that at least one of the wanted texts is in the text of the job and we therefore append it to the jobs list and then we return this list from the function then we say d under name equals main and use this function and if we found suitable chops we create a message and send this message with our send email function so let's run the script and see if it works alright there we received a new mail and we see all the new jobs with information about the company the tax the location and the link to the job post so we can click on the link and apply to the job if we're interested this project is a great example that you can schedule with a cron shop to run daily or maybe once a week so if you want to learn how to do this then i have a tutorial for this that i link here next we implement a price tracker and send us emails whenever the price falls below our given limit for this we look up the product at amazon and then we want to copy the whole url from this site we want to scrape the site to get the name the price and the availability of this item so you want to inspect the page source for this this contains a whole lot of text but i'm simply going to show you the fields we need so we need to search for product title and take this span this contains the title we also need the span with the id price block underscore our price which contains the price as a string lastly we check for the availability id and we are also interested in the class a dash color success so a quick note here these exact attributes only work on amazon.com so you might have to adapt this a little bit in your country okay so now let's remember these attributes for later and to implement our web scraper we install beautiful soup and lxml which is needed to parse the website we then import requests beautiful soup unicode data and again our send email function then we set up a header with the user agent and define a function get product info that takes an url we send a get request to the url and then set up beautiful soup to scrape the site then we look for the title and the price by saying soup.find with the ids i showed you earlier if nothing is found we return nuns if this worked then we continue and say soup dot select and select the availability and the a dash color success class if this works as well we know the item is in stock so the last thing we have to do is convert the price string to a float so we have to get the normal form for the unicode string replace the comma with a dot and get rid of the dollar sign before casting it to a float if everything was successful we return the title the price and the availability from this function in our main section we define the url and the lower price limit we want to check so here you can define and track multiple products in this list then we iterate over the products call our function and keep the product only if it is available and if the price is below the limit we want if this is the case and we have products below the limit then we set up a message again and use the send mail function now let's run the script and check if it works alright there's our mail because we specified 700 and the price is currently at 5.99 we can then click on the link and go ahead and buy the item if you want now the last thing to do again is to set up a crown job like i mentioned before the next project is cool if you want some variation for your desktop background and if you like space images because we're going to get the nasa picture of the day and set this as our background now this script works on mac and linux only for windows you have to figure out the system command for yourself we again need requests for this and some built-in modules we can specify the url to the nasa website actually you need an api key for this but i found out that you can just use the key demo underscore key and it works for the single request then we first define a helper function to get the full absolute path to your download folder for your username so this is where we're going to save the image then we define a function to download the picture we send a request to the url and if this is successful we check for the url key of the json response this should have a jpeg ending in its name and on some days this is not the case because sometimes they share a video there but if we have a picture we again send a request to the picture url then we open a new file and write the content of this picture into it so here essentially we saved picture in our downloads folder then again we run our script as main process and download the picture next we set up a special command to set this file as our background image again these work only on mac or linux and lastly we call os dot system command to actually execute this all right now let's run the script and it worked so there we have our new background image so now you can schedule this to run once a day the last project is the most challenging one but also the most interesting because it challenges you to work with multiple apis we are going to build a script that posts tweets on twitter for us so we are going to work with the twitter api and we use google sheets as our backend that's why we have to install tweepy and g spread and we also install python minus dot and to work with environment variables alright now before we can start we need to put in some work and set up a few things in order to use all those apis the first thing we have to do is to go to console.developers.google.com create a new project and then search for google sheets api and google drive api and activate them for this project then in your dashboard click on credentials create credentials select service account fill out the fields and download the json file we also have to create a spreadsheet for this and click on share and then share this sheet with the service account email you download it so i show you where you find this email in a second and now the sheet has to have the following structure the first row is the table header where we can see we want to put in the time where this tweet should be posted the tweet message and the value of 0 or 1 indicating if this tweet is already posted be careful here to use the correct header names and the correct time format that we want to use later in our code we also need to enable the twitter api so you have to go to developers.twitter.com apply for a developer account create a new project and then create api keys and secrets here so now we can finally jump to the code so you have to create a dot env file and paste the four keys and secrets you get from the twitter site you also have to put the json file in this directory that you got from the google site in here we also find the client email that we have to use when we share this spreadsheet okay now we import the modules we need load the environment variables and connect to the spreadsheet with the g spread module like so then we load the twitter api credentials and connect to our twitter account with the tweep module then i create a little helper function to get the normalized time so here i simply return date time now and we only have to adapt this if we run the script on a back end that is not in the time zone that we use to specify the tweet time in the spreadsheet for example if we use heroku to host the script then feel free to modify this then we write a function check and update tweets here we get all the spreadsheet entries by calling worksheets.getallrecords then we iterate over the rows and get all column entries if the tweet was not already posted so if not done and if the post time is smaller than the current time we want to send out this tweet so we simply have to call tweet api dot update status with this message and then we also change the value of done column to a1 alright so let's check out the script as well and we see our google sheet done column changes from zero to one and now let's have a look at my twitter page so yeah there is the new tweet so this worked as well great again i recommend to run the script with a crown chopped regularly maybe multiple times a day okay so that's it i hope you enjoyed this and then i hope to see you in the next video bye

Original Description

In this Tutorial I share quick Python Automation Ideas that you can use everyday to simplify your life. ✅ Write cleaner code with Sourcery, instant refactoring suggestions in VS Code & PyCharm: https://sourcery.ai/?utm_source=youtube&utm_campaign=pythonengineer * ⭐ Join Our Discord : https://discord.gg/FHMg9tKFSN 🚀🚀 Get monthly Python and ML Tips: https://www.python-engineer.com/newsletter/ 🚀🚀 SUPPORT ME ON PATREON: https://www.patreon.com/patrickloeber If you enjoyed this video, please subscribe to the channel! Code: https://github.com/patrickloeber/python-task-automation Cronjob Tutorial: https://www.python-engineer.com/posts/cron-jobs-for-python/ Timeline: 00:00 - Introduction 00:19 - Send Emails 01:10 - Job Board Scraper 03:21 - Price Tracker 06:15 - Background Image 08:00 - Tweet Scheduler You can find me here: Website: https://www.python-engineer.com Twitter: https://twitter.com/patloeber GitHub: https://github.com/patrickloeber Music: https://www.bensound.com/ Photo by Arnold Francisca: https://unsplash.com/photos/nPhl2x4fk2s #Python ---------------------------------------------------------------------------------------------------------- * This is a sponsored or an affiliate link. By clicking on it you will not have any additional costs, instead you will support me and my project. Thank you so much for the support! 🙏
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Patrick Loeber · Patrick Loeber · 0 of 60

← Previous Next →
1 Lists in Python - Advanced Python 01 - Programming Tutorial
Lists in Python - Advanced Python 01 - Programming Tutorial
Patrick Loeber
2 Tuples in Python - Advanced Python 02 - Programming Tutorial
Tuples in Python - Advanced Python 02 - Programming Tutorial
Patrick Loeber
3 Dictionaries in Python - Advanced Python 03 - Programming Tutorial
Dictionaries in Python - Advanced Python 03 - Programming Tutorial
Patrick Loeber
4 Sets in Python - Advanced Python 04 - Programming Tutorial
Sets in Python - Advanced Python 04 - Programming Tutorial
Patrick Loeber
5 Strings in Python - Advanced Python 05 - Programming Tutorial
Strings in Python - Advanced Python 05 - Programming Tutorial
Patrick Loeber
6 Collections in Python - Advanced Python 06 - Programming Tutorial
Collections in Python - Advanced Python 06 - Programming Tutorial
Patrick Loeber
7 Itertools in Python - Advanced Python 07 - Programming Tutorial
Itertools in Python - Advanced Python 07 - Programming Tutorial
Patrick Loeber
8 Lambda in Python - Advanced Python 08 - Programming Tutorial - Map Filter Reduce
Lambda in Python - Advanced Python 08 - Programming Tutorial - Map Filter Reduce
Patrick Loeber
9 Exceptions in Python - Advanced Python 09 - Programming Tutorial
Exceptions in Python - Advanced Python 09 - Programming Tutorial
Patrick Loeber
10 Logging in Python - Advanced Python 10 - Programming Tutorial
Logging in Python - Advanced Python 10 - Programming Tutorial
Patrick Loeber
11 JSON in Python - Advanced Python 11 - Programming Tutorial
JSON in Python - Advanced Python 11 - Programming Tutorial
Patrick Loeber
12 Random Numbers in Python - Advanced Python 12 - Programming Tutorial
Random Numbers in Python - Advanced Python 12 - Programming Tutorial
Patrick Loeber
13 Decorators in Python - Advanced Python 13 - Programming Tutorial
Decorators in Python - Advanced Python 13 - Programming Tutorial
Patrick Loeber
14 Generators in Python - Advanced Python 14 - Programming Tutorial
Generators in Python - Advanced Python 14 - Programming Tutorial
Patrick Loeber
15 Threading vs Multiprocessing in Python - Advanced Python 15 - Programming Tutorial
Threading vs Multiprocessing in Python - Advanced Python 15 - Programming Tutorial
Patrick Loeber
16 Threading in Python - Advanced Python 16 - Programming Tutorial
Threading in Python - Advanced Python 16 - Programming Tutorial
Patrick Loeber
17 Multiprocessing in Python - Advanced Python 17 - Programming Tutorial
Multiprocessing in Python - Advanced Python 17 - Programming Tutorial
Patrick Loeber
18 Function arguments in detail - Advanced Python 18 - Programming Tutorial
Function arguments in detail - Advanced Python 18 - Programming Tutorial
Patrick Loeber
19 The asterisk (*) operator in Python - Advanced Python 19 - Programming Tutorial
The asterisk (*) operator in Python - Advanced Python 19 - Programming Tutorial
Patrick Loeber
20 Shallow vs Deep Copying in Python - Advanced Python 20 - Programming Tutorial
Shallow vs Deep Copying in Python - Advanced Python 20 - Programming Tutorial
Patrick Loeber
21 Context Managers in Python - Advanced Python 21 - Programming Tutorial
Context Managers in Python - Advanced Python 21 - Programming Tutorial
Patrick Loeber
22 KNN (K Nearest Neighbors) in Python - Machine Learning From Scratch 01 - Python Tutorial
KNN (K Nearest Neighbors) in Python - Machine Learning From Scratch 01 - Python Tutorial
Patrick Loeber
23 Linear Regression in Python - Machine Learning From Scratch 02 - Python Tutorial
Linear Regression in Python - Machine Learning From Scratch 02 - Python Tutorial
Patrick Loeber
24 Logistic Regression in Python - Machine Learning From Scratch 03 - Python Tutorial
Logistic Regression in Python - Machine Learning From Scratch 03 - Python Tutorial
Patrick Loeber
25 Linear and Logistic Regression in 60 lines of Python - Machine Learning From Scratch 04
Linear and Logistic Regression in 60 lines of Python - Machine Learning From Scratch 04
Patrick Loeber
26 Naive Bayes in Python - Machine Learning From Scratch 05 - Python Tutorial
Naive Bayes in Python - Machine Learning From Scratch 05 - Python Tutorial
Patrick Loeber
27 Perceptron in Python - Machine Learning From Scratch 06 - Python Tutorial
Perceptron in Python - Machine Learning From Scratch 06 - Python Tutorial
Patrick Loeber
28 SVM (Support Vector Machine) in Python - Machine Learning From Scratch 07 - Python Tutorial
SVM (Support Vector Machine) in Python - Machine Learning From Scratch 07 - Python Tutorial
Patrick Loeber
29 Decision Tree in Python Part 1/2 - Machine Learning From Scratch 08 - Python Tutorial
Decision Tree in Python Part 1/2 - Machine Learning From Scratch 08 - Python Tutorial
Patrick Loeber
30 Decision Tree in Python Part 2/2 - Machine Learning From Scratch 09 - Python Tutorial
Decision Tree in Python Part 2/2 - Machine Learning From Scratch 09 - Python Tutorial
Patrick Loeber
31 Random Forest in Python - Machine Learning From Scratch 10 - Python Tutorial
Random Forest in Python - Machine Learning From Scratch 10 - Python Tutorial
Patrick Loeber
32 PCA (Principal Component Analysis) in Python - Machine Learning From Scratch 11 - Python Tutorial
PCA (Principal Component Analysis) in Python - Machine Learning From Scratch 11 - Python Tutorial
Patrick Loeber
33 K-Means Clustering in Python - Machine Learning From Scratch 12 - Python Tutorial
K-Means Clustering in Python - Machine Learning From Scratch 12 - Python Tutorial
Patrick Loeber
34 Anaconda Tutorial - Installation and Basic Commands
Anaconda Tutorial - Installation and Basic Commands
Patrick Loeber
35 PyTorch Tutorial 01 - Installation
PyTorch Tutorial 01 - Installation
Patrick Loeber
36 PyTorch Tutorial 02 - Tensor Basics
PyTorch Tutorial 02 - Tensor Basics
Patrick Loeber
37 PyTorch Tutorial 03 - Gradient Calculation With Autograd
PyTorch Tutorial 03 - Gradient Calculation With Autograd
Patrick Loeber
38 PyTorch Tutorial 04 - Backpropagation - Theory With Example
PyTorch Tutorial 04 - Backpropagation - Theory With Example
Patrick Loeber
39 PyTorch Tutorial 05 - Gradient Descent with Autograd and Backpropagation
PyTorch Tutorial 05 - Gradient Descent with Autograd and Backpropagation
Patrick Loeber
40 PyTorch Tutorial 06 - Training Pipeline: Model, Loss, and Optimizer
PyTorch Tutorial 06 - Training Pipeline: Model, Loss, and Optimizer
Patrick Loeber
41 PyTorch Tutorial 07 - Linear Regression
PyTorch Tutorial 07 - Linear Regression
Patrick Loeber
42 PyTorch Tutorial 08 - Logistic Regression
PyTorch Tutorial 08 - Logistic Regression
Patrick Loeber
43 PyTorch Tutorial 09 - Dataset and DataLoader - Batch Training
PyTorch Tutorial 09 - Dataset and DataLoader - Batch Training
Patrick Loeber
44 PyTorch Tutorial 10 - Dataset Transforms
PyTorch Tutorial 10 - Dataset Transforms
Patrick Loeber
45 Download Images With Python Automatically - Python Web Scraping Tutorial
Download Images With Python Automatically - Python Web Scraping Tutorial
Patrick Loeber
46 PyTorch Tutorial 11 - Softmax and Cross Entropy
PyTorch Tutorial 11 - Softmax and Cross Entropy
Patrick Loeber
47 Select Movies with Python - Web Scraping Tutorial
Select Movies with Python - Web Scraping Tutorial
Patrick Loeber
48 PyTorch Tutorial 12 - Activation Functions
PyTorch Tutorial 12 - Activation Functions
Patrick Loeber
49 List Comprehension in Python - A Python Feature You MUST KNOW - Python Tutorial
List Comprehension in Python - A Python Feature You MUST KNOW - Python Tutorial
Patrick Loeber
50 PyTorch Tutorial 13 - Feed-Forward Neural Network
PyTorch Tutorial 13 - Feed-Forward Neural Network
Patrick Loeber
51 How To Add A Progress Bar In Python With Just One Line - Python Tutorial
How To Add A Progress Bar In Python With Just One Line - Python Tutorial
Patrick Loeber
52 PyTorch Tutorial 14 - Convolutional Neural Network (CNN)
PyTorch Tutorial 14 - Convolutional Neural Network (CNN)
Patrick Loeber
53 The Walrus Operator - New in Python 3.8 - Python Tutorial
The Walrus Operator - New in Python 3.8 - Python Tutorial
Patrick Loeber
54 PyTorch Tutorial 15 - Transfer Learning
PyTorch Tutorial 15 - Transfer Learning
Patrick Loeber
55 YouTube Data API Tutorial with Python - Analyze Channel Statistics - Part 1
YouTube Data API Tutorial with Python - Analyze Channel Statistics - Part 1
Patrick Loeber
56 YouTube Data API Tutorial with Python - Find Channel Videos - Part 2
YouTube Data API Tutorial with Python - Find Channel Videos - Part 2
Patrick Loeber
57 YouTube Data API Tutorial with Python - Get Video Statistics - Part 3
YouTube Data API Tutorial with Python - Get Video Statistics - Part 3
Patrick Loeber
58 YouTube Data API Tutorial with Python - Analyze the Data - Part 4
YouTube Data API Tutorial with Python - Analyze the Data - Part 4
Patrick Loeber
59 AdaBoost in Python - Machine Learning From Scratch 13 - Python Tutorial
AdaBoost in Python - Machine Learning From Scratch 13 - Python Tutorial
Patrick Loeber
60 Ultimate FREE Study Guide for Machine Learning and Deep Learning
Ultimate FREE Study Guide for Machine Learning and Deep Learning
Patrick Loeber

Related Reads

📰
The Only AI Tools a Small Business Actually Needs in 2026
Discover the essential AI tools for small businesses in 2026 to boost efficiency and customer engagement
Dev.to AI
📰
I Built an AI Life Planner the Month I Graduated and Switched to Linux Halfway Through
Learn how to build a personal AI life planner by following the author's journey, from initial development to switching to Linux halfway through, and apply these skills to your own projects
Dev.to · Hilal
📰
Your Second Brain Is a Graveyard. Your AI Has Amnesia. (Part 1)
Learn why your second brain and AI tools are failing you and how to address these issues
Medium · AI
📰
The Python Automation Business I Started With 200 Lines of Code Eventually Replaced My Freelance…
Learn how a simple 200-line Python script can turn into a full-fledged automation business, replacing freelance work
Medium · Programming

Chapters (6)

Introduction
0:19 Send Emails
1:10 Job Board Scraper
3:21 Price Tracker
6:15 Background Image
8:00 Tweet Scheduler
Up next
How AI Is Transforming Analytics in Tableau Cloud & Server
Salesforce Product Center
Watch →