How to Automate the Cool and Awesome Stuff with Python
A guide to automating Pdf Extractor, Send SMS, PyWhatsapp, Control keyboard and Mouse, Photo editing, and much more using Python.

In this blog, I will share some snippet codes for automating the cool and awesome stuff. This will be your toolbox for automating the things you use daily.
1. PDF to Text
You can convert Pdf to Text with the following simple code. I had to use PdfPlumber to extract text from any Pdf file.
# PDF to Textimport pdfplumberpdf = pdfplumber.open('myfile.pdf')
print("No of Pages: ", print(len(pdf.pages))
page = pdf.pages[0] # Scraping page
Text = page.extract_text()
print(Text)pdf.close()2. PyWhatsapp
You can send WhatsApp messages using the Pywhatsapp module. Below I gave an example code that you can use.
import pywhatkit as pypy.sendwhatmsg_instantly("+1xxxxxxxxxxx", "hello their") # send message instantlypy.sendwhats_image(phone_no="+1xxxxxxxxxxx", img_path="image.jpg", caption="Hey! this is Pywhatsapp") # Send imagepy.sendwhatmsg("+1xxxxxxxxxxx", "hello their", 15, 2) # Send message with Scheduling3. Image Editing
Edit your image programmatically with the Python Pillow library. Below I gave some image editing functions code. To create more image editing features check out the Pillow documentation.
# Edit Image with Python# Enhanced Imagefrom PIL import Image,ImageFilter
from PIL import ImageEnhanceimg = Image.open('img.jpg')
img.show()
enh = ImageEnhance.Contrast(img)
enh.enhance(1.8).show("30% contrast more")# change Image Typlefrom PIL import Image
image = Image.open('img.jpg')
image.save('new_img.png')# Resizing Imagefrom PIL import Imageimg = Image.open('img.jpg')
new_img = img.resize((500, 500))
new_img.save('resize.jpg')
print(img.size) # Output: (1920, 1280)
print(new_img.size) # Output: (500, 500)# Flipping imageimg = Image.open('img.jpg')
img_flip = img.transpose(Image.FLIP_LEFT_RIGHT)
img_flip.save('img_flip.jpg')4. Controlling Keyboard and Mouse
Python can also be used to automate your operating system including Keyboard and Mouse. Below I mention some useful code. For a full guide look for pyautogui documentation.
# Controling Keyboard and Mouseimport pyautogui# Control MousecurrentX, currentY = pyautogui.position() # Current X and Y location
pyautogui.moveTo(100, 150) # move mouse to x, y direction
pyautogui.click() # click mouse on current location
pyautogui.doubleClick() # click mouse on current location# Control Keyboardpyautogui.write("Hello Pythoneer") # Write
pyautogui.write(['right', 'right', 'right']) # Press multiple
pyautogui.press("enter") # Press a key
pyautogui.hotkey('ctrl', 'c') # Press combo keys
pyautogui.keyUp('ctrl')
pyautogui.keyDown('ctrl')5. Send Email
This simple Snippet code will help you to Send Emails with Python. You can send emails to GMAIL, Yahoo, and also third-party mails.
import smtplib
from email.mime.text import MIMETextsender = '[email protected]'
receivers = '[email protected]'
body_of_email = 'The body of the email'
msg = MIMEText(body_of_email, 'plain')msg['Subject'] = 'Enter Subject'
msg['From'] = sender
msg['To'] = receivers = smtplib.SMTP_SSL(host = 'smtp.gmail.com', port = 465)
s.login(user = 'email', password = 'password')
s.sendmail(sender, receivers, msg.as_string())
s.quit()6. Send Text Message
Not only Sending Email Python can also be used to Send Mobile Text Messages. You need a Twilio API key from the Twilio website and next, you need to follow the below sample code.
# Send Text Messagesfrom twilio.rest import Client
account_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXX'
auth_token = 'your_auth_token'
client = Client(account_sid, auth_token)
message = client.messages.create(from_='+1xxxxxxxxxx', body ='Enter Text Message', to ='+1xxxxxxxxxx')
print(message.sid)7. Read Excel File
You probably use the Pandas module to read Excel files in Python. But I had another library name openpyxl which is specially developed to read Excel files. Check out the below sample code.
# Excel Readingimport openpyxlwb = openpyxl.load_workbook("filename.xlsx")
sheet = wb.activefor i in range(sheet.max_column):
print("Column: ", i)
for r in sheet.iter_rows():
print(r[i].value)8. Scrape Websites
You can scrape websites in Python using two modern modules. Below I gave a sample code that you can use to scrape websites data.
# Scrape Websitesimport requests
from bs4 import BeautifulSoupr = requests.get("xyz.com")soup = BeautifulSoup(r, "html5lib").textprint(soup.prettify())print("Title: ")title = Soup.find("title")
Content = Soup.find("div", attrs = {"class" : "Content"})9. Develop Games
You can some nice 2d games in Python with third-party and built-in modules. Below is a tic-tac-toe game example coded in Python.
from turtle import *
from freegames import linedef grid():
"Draw tic-tac-toe grid."
line(-67, 200, -67, -200)
line(67, 200, 67, -200)
line(-200, -67, 200, -67)
line(-200, 67, 200, 67)def drawx(x, y):
"Draw X player."
line(x, y, x + 133, y + 133)
line(x, y + 133, x + 133, y)def drawo(x, y):
"Draw O player."
up()
goto(x + 67, y + 5)
down()
circle(62)def floor(value):
"Round value down to grid with square size 133."
return ((value + 200) // 133) * 133 - 200state = {'player': 0}
players = [drawx, drawo]def tap(x, y):
"Draw X or O in tapped square."
x = floor(x)
y = floor(y)
player = state['player']
draw = players[player]
draw(x, y)
update()
state['player'] = not playersetup(420, 420, 370, 0)
hideturtle()
tracer(False)
grid()
update()
onscreenclick(tap)
done()Final Thoughts
Well, I hope you find these cool stuff automation articles fun and helpful. Feel free to respond and also Share ❤️ this article with Pythonier Friends. Happy Coding!
You can support me by becoming a Medium member, check below. 👇
Never stop learning! Check out my other articles, hope you find them interesting 😃
More content at plainenglish.io





