- Published on
Automate Your Daily Tasks with Python Scripts
- Authors
- Name
- Yashvi Shah
- @yashvidotdev
In this blog, we will explore how to automate simple daily tasks with Python, making your workflow faster and error-free.
Why Automate?
Automation saves time, reduces human error, and lets you focus on high-value tasks. With Python’s powerful libraries, automating small repetitive tasks becomes very straightforward.
Example 1: Rename Multiple Files
Suppose you have a folder with hundreds of files that you want to rename systematically. Here’s how to do it:
import os
folder_path = 'path_to_folder'
for count, filename in enumerate(os.listdir(folder_path)):
dst = f"file_{str(count)}.jpg" # rename logic here
src = os.path.join(folder_path, filename)
dst = os.path.join(folder_path, dst)
os.rename(src, dst)
print("Files renamed successfully.")
Replace path_to_folder
with your directory path. This will rename files as file_0.jpg
, file_1.jpg
, etc.
Example 2: Sending Emails Automatically
You can send automated emails using Python’s smtplib
. Example:
import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login('your_email@gmail.com', 'your_password')
server.sendmail('your_email@gmail.com', 'receiver_email@gmail.com', 'This is an automated email from Python.')
server.quit()
Note: For Gmail, enable less secure app access or use app passwords for security.
Example 3: Convert Multiple Images to PDF
Convert all images in a folder into a single PDF file:
from PIL import Image
import os
folder = 'images_folder'
images = []
for file in os.listdir(folder):
if file.endswith('.jpg') or file.endswith('.png'):
img = Image.open(os.path.join(folder, file)).convert('RGB')
images.append(img)
images[0].save('output.pdf', save_all=True, append_images=images[1:])
print("PDF created successfully.")
Change 'images_folder'
to your folder containing images.
Final Thoughts
Python automation scripts can simplify your life. Start with simple file operations and emails, then move towards web scraping, API automation, and real-time data pipelines as your skills grow.