Automation. It’s imaginary to remove work. So, why not support it along?
Truth be said, automating even modest tasks robustly
takes time and a lot of dependence management which can become very complex.
Nevertheless, it can be very rewarding to automate some modest
tasks. Even if it was more for fun.
For those that are Python fans already, you know how friendly Python is for co-operating
with just about everything. From sending HTTP requests, interacting with APIs, to loading and managing
databases.
Python is a great choice for automation.
Here are five modest things you can automate that can
help your many workflows and projects.
WhatOthers Do With Python
You’re possibly wondering what people are building with Python in
the real world. So first, let’s take a fast look at how certain of the big tech
companies are using the language.
Google is a company that has used Python from the start, and it’s increased
a place as one of the tech giant’s chief server-side languages. Guido van
Rossum, Python’s Benevolent Dictator for Life, even operated there for some
years, overseeing the language’s development.
Instagram likes Python for its easiness. The service is known for successively “the
world’s largest deployment of the Django web outline, which is written entirely
in Python.”
Spotify places the language to use in its data analysis and
back-end facilities. According to their group, Python’s ease of use tips to a
lightning-fast development pipeline. Spotify accomplishes a ton of analyses to
give references to their users, so they want something that’s simple but also
works well. Python to the rescue!
You can checked out this article to see what further
companies are doing with Python.
If you’re already influenced, then let’s get you ongoing!
WhatYou Can Do With Python
From web development to data science, machine
learning, and more, Python’s real-world applications are infinite. Here are several
projects that will assist you in finally placing your Python skills to good
use.
1. Movingthe Mouse Automatically So Your Skype/Lynk Shows You as Active at Work
Imagine you have been scrolling over the newsfeed of
your favourite social media app for the previous ten minutes. Suddenly,
your Lynk active
symbol turns yellow. You’re inactive and not in a meeting.
Your nosey boss comes over and taps you on the shoulder.
Surprised, you look up to see him conspicuous down at
you. He has a bad habit of micro-managing each second of your time.
“Hey, uh, I want you to relax and all but how is that module
approaching along,” he asks. You grit your teeth and provide some sort of
polite answer.
“Cool, well, I just want to make sure you are fixing.
Janice, our VP, is actually expecting us to meet our deadline.”
End of interaction.
If only Lynk didn’t call you out like that.
Wait, you can get about this. After a few instants of
Googling, you find a script to move your mouse and start coding up a job to run
all few minutes that will make sure your mouse is moving.
These activities of the mouse and the keyboard can help
make it appearance like you are active at work, in the case of Skype or Lynk.
The automation movement usages Python’s PyAutoGUI
module. To install the PyAutoGUI module, run the following command:
pip install pyautogui
Python controls and tracks the mouse by your screen’s coordinate system.
For instance, if you use a 1920x1080 screen resolve, the coordinate system for
your screen would appearance like this:
The following functions are accessible under the PyAutoGUI module:
·
size():
The size() function lets you know your screen resolution.
import pyautogui
print(pyautogui.size())
print(pyautogui.size())
Running this folder (saved as .py extension), the Python code
uses the size() function to give the x, y format of your screen
resolution as output:
·
moveTo():
The moveTo() function in the PyAutoGUI module moves the mouse. The
code below usages the function, which takes the coordinates of x and y, and an
optional duration argument. The function usages a stated time period argument
to move your mouse pointer from a current location to the coordinates of x and
y.
import pyautogui
print(pyautogui.size())pyautogui.moveTo(150,100, duration = 2)
print(pyautogui.size())pyautogui.moveTo(150,100, duration = 2)
Running this Python script wonderfully moves your mouse pointer from its
present position to coordinates (150, 100), taking 2 seconds to
complete the process.
Other than some of these basics, you can also usage functions, such as
click and typewrite, for both click and type strings.
All of which can be used to help confirm that your boss doesn’t catch
you slacking off any time quickly.
2. Automatingthe Website Login Process Using Selenium
Many websites frown on using automated crawlers and programs to log in
to their websites. But, it’s still a excessive skill to have.
Selenium is a beneficial library
that can be used by multiple languages and that can support automate UI QA, or
even to scrape websites with a login.
Although learning Selenium can take specific time, start small. Just
build a tool that can log in to your favourite website.
To get started, it’s vital that you install Chrome Driver and the Selenium
library for Python. Usage the command below to add the Selenium library.
pip install Selenium
To start, we want to import some selected modules from Python’s Selenium
library. Add the command below:
From selenium import webdriverdriver = webdriver.Chrome()
Now, to automate the login procedure, we start with a modest task like a
login form for a website.
The task entails:
·
Navigating to the website.
·
Finding login fields (usually
username and password).
·
Filling in your login details.
·
Submitting login details to
get you through the login screen automatically.
Tip: You may choose to
define a “method” (for frequent logins) to allow reuse in other tests.
The code lines would look similar to:
As you will notification, you need to get the elements you want to interrelate
with. This is arguably one of the harder parts of making a web-scraper or
automated script that logs in to websites.
There are some ways to detect the elements of a web application to find
the login fields.
Common ways of finding elements include ID (like the example above), CSS
selectors, name, and XPaths.
A different approach to detecting elements for the login process can be
found in the official documentation of Selenium. Some websites engage extra dynamic content (like several JavaScript!).
Overall, watching Selenium automatically click buttons and log in to
your favourite websites is mesmerizing. Things just start moving and working
without your interaction.
Almost like magic!
Creating automatic backup files can be very beneficial if you perform
regular backups.
You may be conversant with ZIP files (files with the .zip extension).
ZIP files can contain some files with their compressed contents. And, as ZIP
files can also hold many files and subfolders, it becomes a handy way to backup
files by packaging them into one.
A single ZIP file, called an archive file, can be generated
automatically using Python functions in the zipfile
module.
You can also open (or extract) ZIP files using Python. The script is
shared below.
This script was occupied from the book Automate the Boring Stuff with Python (in case you want even more ideas).
Another one-off idea that we just saw and thought was an interesting way of automating tasks
you might do fairly often, is using a script to post multiple videos to Reddit.
·
Posting YouTube videos in
Reddit threads can also be automated.
·
The usage of PRAW, a Python wrapper that allows you to scrape data, can offer much extra
to your Reddit experience.
·
To get started, install PRAW using pip.
·
The script below
automatically posts YouTube videos to Reddit threads.
5. Automate theBoring Stuff
This is a source on “practical programming for total beginners.”
Like the title says, this book will teach you how to automate tedious tasks
such as updating spreadsheets or renaming files on your PC.
·
It’s the perfect starting point for anybody who’s mastered the
basics of Python.
·
You’ll get a chance to repetition what you’ve educated so far by
making dictionaries, scraping the web, working with files, and creating objects
and classes.
·
The hands-on requests that you come across in this book will
provide you with real-world results that you can see immediately.
This source is accessible in different formats to give you the top
learning experience possible. Buy the book on Amazon or read it online for free.
6. Create a
Calculator
This modest project is a solid gateway into GUI programming.
Building back-end facilities is one significant part of deployment, but there
may be a front-end that needs to be occupied into account. Making applications
that users can simply interact with is paramount.
If you’re interested in UX and UI design, then take a look at
this tutorial.
You’ll be working with the
tkinter
module, the normal graphical user
interface package that comes traditionally bundled with Python.
·
The
tkinter
module
is a wrapper around Tcl/Tk, a combination of the Tcl scripting language and a
GUI outline extension, Tk. If you have Python installed, then you should
already have the tkinter
framework
prepared to go as well. A simple call will get you started:fromtkinter
import
*
·
Once you’ve got that set up, you can get to work on building your first GUI
calculator in Python.
·
Practice using the
tkinter
module and watch your idea
materialize on the screen. Then, once you’ve got your feet wet, you can branch
out and start working with Python’s additional GUI toolkits. Check out the
official documentation on GUI Programming in Python for
more information.
7. Conclusion
·
Automating tasks can be a lot
of fun. Watching your program automatically log in to your favourite website,
or load hundreds of files into a database, can make you feel as if you have re-designed the wheel.
·
And, there are a lot of excessive
libraries out there that can help you automate tasks simply. Excel reports, emails, and
other tasks can be simplified in a few lines of code.
0 Comments