Essential Python Scripts to Simplify Your Daily Tasks
Written on
Automating Your Everyday Activities
If you are on the lookout for tools to simplify your daily tasks, these four Python scripts can be incredibly helpful. Bookmark this article and let’s dive right in!
The Core of Automation: Desktop Task Control
For those who wish to automate tasks on their computer, the following script is invaluable. It utilizes the Pynput library to manage keyboard and mouse functions, allowing for actions such as typing, clicking, and moving the cursor.
# Auto Keyboard and Mouse
# pip install pynput
from pynput.keyboard import Key, Controller
from pynput.mouse import Button, Controller
# Keyboard automation
keyboard = Controller()
# Type a message
keyboard.type('Hello, World!')
# Execute enter key
keyboard.press(Key.enter)
keyboard.release(Key.enter)
# Mouse automation
mouse = Controller()
# Adjust mouse position
mouse.position = (10, 20)
# Perform a click
mouse.click(Button.left, 1)
# Scroll the mouse
mouse.scroll(0, 2)
# Drag action
mouse.press(Button.left)
mouse.release(Button.left)
# Current mouse position
print('Current pointer position is {0}'.format(mouse.position))
Managing CSV Files Without Pandas
If you prefer to avoid using Pandas for handling CSV files, consider this straightforward automation script that leverages Python's built-in CSV module. It effectively reads, writes, and appends data to CSV files, making it a lightweight solution for developers looking to automate their CSV tasks.
# Read/Write CSV
import csv
# Reading CSV
with open('data.csv', 'r') as file:
reader = csv.reader(file)
for row in reader:
print(row)
# Writing CSV
with open('data.csv', 'w') as file:
writer = csv.writer(file)
writer.writerow(['Name', 'Age'])
writer.writerow(['Alice', 25])
writer.writerow(['Bob', 30])
writer.writerow(['Charlie', 35])
# Appending CSV
with open('data.csv', 'a') as file:
writer = csv.writer(file)
writer.writerow(['David', 40])
writer.writerow(['Eve', 45])
Extracting Text from PDFs Efficiently
For those dealing with numerous PDF documents, this Python script is perfect for extracting text, even from complex layouts. It employs the PdfPlumber library for accurate text retrieval.
# Get PDF Text
# pip install pdfplumber
import pdfplumber
def get_pdf_text(pdf_path):
with pdfplumber.open(pdf_path) as pdf:
text = ''
for page in pdf.pages:
text += page.extract_text()return text
if __name__ == '__main__':
pdf_path = 'test.pdf'
text = get_pdf_text(pdf_path)
print("Extracted Text: ", text)
Creating Strong, Unique Passwords
If you require a robust and unique password, this Python script can generate one for you. It utilizes the random and string modules to create a secure password.
# Generate Passwords using Python
import random
import string
def generate_password(length=12):
characters = string.ascii_letters + string.digits + string.punctuation
password = ''.join(random.choice(characters) for _ in range(length))
return password
# Generate a password of length 12
password = generate_password()
print("Generated Password:", password)
Final Thoughts
Automation scripts can significantly ease the burden of repetitive tasks in our daily lives. If you found this article helpful, feel free to share it with your friends and give it a clap!
"Keep Sharing, Keep Learning"
Support me by tipping below so I can grab a coffee. ☕ Never stop learning, and here’s a collection of my favorite programming articles for you to explore.
In Plain English 🚀
Thank you for being part of the In Plain English community! Before you go, make sure to clap and follow the author!
Follow us: X | LinkedIn | YouTube | Discord | Newsletter
Check out more content at Stackademic | CoFeed | Venture | Cubed
Find additional resources at PlainEnglish.io