Process Automation with Python

This is a subject of which I am extremely, some would even say irresponsibly, passionate about. Programming, in general, is every bit as much my hobby as it is my job. Without hesitation, I'd go as far as to say it's who I am. My identity. What does this mean, exactly? It means that in every moment of my day, I'm thinking about how I can use this skill set to improve not only my life but the lives of those around me. Barring a few exceptions, such as a WordPress website, I almost always reach for Python for these kinds of passion projects to make things easier or more fun. I've briefly touched on this before but I think now it's time we re-visit the subject and share not only some things we've used it for in the past, but also some things we want to do with it in the future.

A Little History

Python is old, originally created back in 1990. But old doesn't mean bad. Even though it's knocking on 30, it has years (decades, even) of improvements, frameworks, documentation, and other things just waiting to be used by those who choose to use it. But why the name, "Python"? I'm glad you asked. Apparently, the creator of Python, a Dutch developer named Guido van Rossum, was stuck on what to officially call his language. He had nick-named the language "python" after the sketch comedy show "Monty Python". But as time went on, the name just kind of... stuck.

Remnants of this can still be found all over the place. Though the language itself lacks any direct references, Python tutorials all over the web are filled with references to Life of Brian, Holy Grail, and pretty much every other Monty Python skit you can think of.

File Editing Made Instant?

I think we've already discussed this particular example, but let's review it. At one point in my career here at Red Shark Digital, a team member had a particularly annoying and tedious task. A few times a week, he had to make line-by-line edits to a CSV file to put it in the correct format so that it could be read properly by another program. It was all repetitive work, like "Put columns 2, 3, and 4 together" or "Change this '7995' to read '$7.995.00 USD'. And each of these changes had to be done for each row, for a few hundred rows.

I had overheard this particular team member, let's call him "Travis", mention on several occasions how tedious of a task it was. I hadn't really played with Python much up to this point, but I knew what it was capable of and most often used for. So began the perfect task for me to use as a catalyst to take my first baby steps into the language.

In coding terms, this thing probably wasn't pretty. Held together with sticks and twigs, running on hopes and dreams, the script somehow managed to work without fail. Full disclosure, however, we only ended up using it 2-3 times before we didn't need it anymore. But for me, it was a new sub-hobby.

Cron Jobs for Business

In the Linux world (UNIX, really, so that also includes Mac OS) "Cron" is a job scheduler built into the operating system. With a pretty simple line of code being added to the right file, you can basically tell the computer, "Hey. go do this thing at X interval." This could be daily, weekly, monthly, or even something custom like, "every 5 minutes", such as was used in a recent little excursion of mine.

When you have a lot of projects, it's good to keep things partitioned. You know, the whole "don't put all your eggs in one basket" mentality. Because of this, we have several different servers that we use for different things. And if a server goes down, you may not always find out about it right away. Obviously, the sooner you can discover an issue, the sooner you can resolve it. So, we have a little program that runs every 5 minutes, quietly in the background and performs a simple ping check on all the servers we have listed. If there's an issue, I get notified right away.

Cron Jobs for Personal Uses

Not all projects have to be productive. I have a fun project that I've been working on a little bit every now and then that is, while arguably a little over-kill, also pretty damn cool. The idea is to have several Raspberry Pi computers hooked up to a small 8-12" touchscreen scattered throughout the house that would basically serve as digital picture frames. Now of course, I could just buy digital picture frames and get the same result, right? Well with a little pythonic imagineering, I can take it one step further.

Soon, I'll have a Synology media center in my house. Mostly, it'll be used to store old DVD's that I can stream from my house. But the idea here is to also have a set of directories, one for each digital picture frame, that will just have a bunch of images. Every minute or so, the raspberry pi will reach out to the media center, find it's specified folder, randomly select an image, and display it on the screen. A minute or two later, it get's another one to show. The benefit to all of this work, however, is having a single location, my media center, that I can change the images on ALL of the picture frames throughout the house.

Any ideas of your own?

I sincerely hope that this has inspired you to find ways to, with or without programming, always be on the lookout for ways to improve. And if we have, we'd love to hear from you! Let us know your ideas of how you've decided to #BeBetter in your everyday life. And if it involves a need for some programming, get in touch with us. Process automation is something we would be more than happy to help you with.