Automate with Python using the Python task automation scripts explained in this post. Download and install the “Top 10 Automatable Tasks” build, which contains a version of Python and all the tools listed in this post.
As a developer, there are always more tasks to complete than you have time for in a day. While it’s important to prioritize time-sensitive, impactful or blocking issues, they’re usually not the kind of things that can be knocked off your list quickly. If you try breaking down bigger tasks into smaller subtasks, you just end up increasing the list of things that still need to get done. But what if you could knock off some of these subtasks in no time at all? That’s where Python comes in.
Python is an incredibly powerful and flexible open-source language that is used in all layers of the application stack across the technology industry: from data manipulation processing real-time data feeds, to serverless applications processing commands from your personal voice assistant to being a rock-solid, general-purpose language for traditional applications.
Because of this flexibility and breadth of capabilities – extended by its extensive library of plugins – Python is an amazing tool. It can be used to build all the little scripts and utilities that simplify and automate with Python, your life as a software developer or system administrator.
Automate with Python: Getting Started
This post goes through a series of scripts that can be run on multiple platforms (Windows, Mac and Linux) to accomplish common tasks. To get started, you can:
To minimize it click the little top left minimize button and the MiniCLIP will hide into a Tray. To open it back simply click on the icon in Tray (Multi Clipboard). Note: If MiniCLIP is already visible and you click on the Tray icon anyway, it will move the MiniCLIP window to the latest stored position. MiniCLIP records the last position when. Get your hands on Zazzle’s wonderful Mini clipboards. Whether for school or work shop amazing designs & images for your new clipboard.
You can review all the relevant source code in my Python Scripts GitHub repo.
![]()
All set? Let’s go.
Top 10 Python Task Automation Scripts#1 checkjson
This script will read a file and either pass the file as being a valid JSON file, or die a horrible death. But for all practical reasons, it tells me if the error is in the file or the program that I am trying to load the file into.
To run it:
That’s all you need to validate JSON, but it can easily be modified to validate YAML, as well.
#2 checkyaml
Kubernetes is difficult enough without having YAML fail to parse. This utility is a way to validate that the YAML is valid. Use it before ripping apart the program you are trying to load it into.
To run it:
Now that we’ve validated that we’re dealing with JSON and YAML, how can we convert between them?
#3 json2yaml
If you work with config files or need to expose YAML via an API, you’ll probably find yourself needing to convert a file from JSON to YAML. The output can either be sent to stdout or to a specified file.
To run it:
But what if you need to go in the other direction, from YAML to JSON?
#4 yaml2json
This script converts a file from YAML to JSON. The output can either be sent to stdout or to a specified file.
To run it:
Miniclip 3 2 – Universal Clipboard Printing Machine
Manipulating JSON and YAML are great options for dealing with text input, but what if your input is a graphic file instead?
#5 convert2jpg
When dealing with older systems that require you to upload images, such as defect tracking applications or expense management solutions, it seems like they all accept JPEG images but rarely accept newer formats, such as PNG or HEIC.
To resolve this issue, here’s a quick utility that will take the input file and convert it to a .jpg version using the same base name.
To run it:
Even more common than dealing with graphic files is copying and pasting info to/from the clipboard. But is there a way to do it without having to open an editor every time?
#6 copy2clip
Copying the contents of a text file to the clipboard is an all-too-frequent task, whether it’s a log file someone wants to see, a configuration file you need to share, or even an ssh key. Getting to the file is easy enough on the command line, but then having to open it in an editor just to copy-and-paste takes time you don’t need to waste.
The following copy2clip script works on both Windows and Mac, and uses native functionality that is wrapped in a little bit of Python code to load the files into the clipboard.
To run it:
So now that we know how to copy and paste file content quicker and easier, let’s apply it to file names.
#7 cwd
Getting the present working directory is easy on Linux and Mac because it’s built into the shell as the pwd command. But pwd is a POSIX environmental variable, which means it won’t work on Windows. As a result, we can use the command called cwd so it will not interfere if you choose to use it on either Mac or Linux, but is primarily aimed at Windows.
Running cwd on its own will display the current working directory. If you pass the -c flag it automatically copies the current working directory to the clipboard on Mac or Windows, which saves a lot of retyping and mouse movements.
In addition, you can pass a filename as an argument and have its full path copied to the clipboard, which is something I need to do often when running test cases.
To run it:
Let’s change tack and talk math.
#8 quickmath
This script is used to add (or multiply or divide or subtract) multiple numbers in a single command line. The task of calculating values is needed more often than you think, and who wants to open Excel just for that? This automation comes in handy.
To run it:
Now that we can automate math, let’s apply it to currency conversion.
#9 currency
You’ve probably looked up conversion rates using your browser, but here’s how to automate the task of finding the current exchange rate between any two currencies.
To run it:
Now we know that $1 CDN is currently only worth $0.71 USD. Great for Americans; not so great for Canadians, but what about the other NATO countries?
#10 nato-alphabet
Okay, this one is just for fun. This script spells out a word using the NATO phonetic alphabet.
To run it:
Automate with Python: Scripts for Every Developer’s Toolbox
My scripts just scratch the surface of what’s automatable with Python. If you have a function or routine task you want to automate, there are multiple resources online to aid in that pursuit, including:
Next Steps:
Miniclip 3 2 – Universal Clipboard Printing LabelsRelated Blogs:Using clipboard
When you copy something on your PC, it’s automatically copied to your clipboard for you to paste. Now with the October 2018 Windows update, not only can you can paste multiple items from your clipboard history, but you can also pin the items you tend to use all the time and sync your clipboard history to the cloud.
Here are some answers to questions you might have about your clipboard.
How do I turn on my clipboard history for the first time?
To turn your clipboard on for the first time, select Windows logo key + V, and then select Turn on.
How do I sync my clipboard items to my PC?
To turn on the sync feature, select Start > Settings > System > Clipboard . Choose On under Sync across devices.
How do I clear my clipboard history?![]()
To clear everything—except pinned items—on your device and the cloud, select Start >Settings > System> Clipboard > Clear clipboard data > Clear.
You can also clear your device clipboard history by selecting Windows logo key + V and then selecting the Clear all option at the top.
How do I clear an individual item I don't want to show up in the clipboard history anymore?
To clear an item on your clipboard, open your clipboard by selecting Windows logo key + V, and then next to the item in question, select Delete.
How do I sync my clipboard to my phone?
You can't sync your clipboard history to your phone yet, but that feature is coming soon.
Troubleshooting clipboard
I can't see my clipboard history
Make sure you’ve turned on clipboard history. To turn your clipboard on for the first time, select Windows logo key + V and select Turn on.
Clipboard history gets cleared each time you restart your PC, except for those items you’ve pinned.
My clipboard isn't syncing to my devices
To sync your copied items automatically to your other devices select Start > Settings > System > Clipboard . Choose Automatically sync text that I copy.
The sync feature is tied to your Microsoft account, or your work account, so remember to use the same login information on all your devices.
Syncing your clipboard items across your Windows 10 devices requires you to be running the latest Windows 10 update. For more information on updating, see Windows Update: FAQ.
I can't copy items to my clipboard history
Your size limitations are 4 MB per item. Text, HTML, and Bitmap are supported.
My clipboard items are disappearing from my clipboard history
Your clipboard history is limited to 25 copied entries. Older items—unless they're pinned—are removed automatically to make room for new clipboard items.
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |