Ask HN: What Python automation scripts do you reuse frequently at work?
Wondering if there are any automation scripts that people frequently run at work and what the scripts do.
Did you write the scripts to automate your own tasks or for your org/teams' operations?
How often do you run them?
11 comments
[ 2.8 ms ] story [ 34.0 ms ] threadIf I'm doing large scale web development, I tend to use containers, so I'll use a scheduling mechanism appropriate for whatever framework I'm using. For example, if I'm building a Django application, then I use Celery.
There's always the tradeoff of just using the tools you get for free in a Linux distro, but paying the price of handling multiple DSLs, versus installing, configuring, and managing a larger system with a more homogenous interface.
The static site generator on which my websites are built is Python. The linters for those websites' content? Also Python. The UI tests for those websites? Playwright and Python. The code to rebuild the production site when new changes are pushed? Python.
I have a script to start my projects. It puts me in the right directory, sets up the environment, launches the IDE, etc.
I have a lot of small one-time scripts to export, transform and import data.
Basically, if it's more than a few lines of bash, I'll use Python. It's a wonderful language.
Curious, how do you organize or keep track of all your scripts? I assume you have them easily accessible so you can trigger them quickly?
As for organisation, they are usually in the ./scripts directory of their respective projects. Generic ones are in my dotfiles: https://github.com/nicbou/dotfiles
Not only to make specific tasks, but also, to remove the burden in some of them, why ssh/rdp to a server to execute something if we can quickly create a script and run it with a click?
At home? domotics, remembering to close the blinds or turn off apliances? no thanks, HA takes care of it with schedules and conditions. Leaving home and remembering to turn on the alarm? no thanks, geolocation + condition, if away for more than 5 minutes, assume that I left and close everything, shut down stuff, turn on the alarm, start the vacuum and get a notification on the mobile.
My python script takes all our employee headshots and makes everybody a unique bingo card (obviously excluding their own headshot). Then they bring their bingo card to our virtual weekly Coffee Chats and get to mark off somebody else who is there.
First person to get a row wins a small prize (coffee gift card) and then we usually have a second place as well (submarine shape gets a sub sandwich gift card) — after that enthusiasm starts to fall off. Helps the new people to get to meet more people than they would if there wasn’t a gameified incentive.