Sunday, April 30, 2017

A chapter in my life: Leadership Course and Flask

The last few months have been absolutely insane. I just finished with a 3-month leadership course for College, bringing me to the two-year mark in my degree. This was a particularly challenging course because it involved a lot of interaction with other people. These interactions happened a few different ways: talking to people I already knew at work and Church, group chats online and also a 4-day long "Capstone" that I went to in Estes Park, Colorado. That was a ton of fun!

The weeks after have been hard. Some of that I credit to the fact that something really fun had just ended, but I think there was just a lot of stress, too. Finishing up the rest of the course, taxes, meetings with people--not to mention my car had a timing belt go out, which meant the engine pretty much blew up! Everything piled on and it was really tough for a while there. But my taxes are now done, I have a new (to me) car and the course is completed. I think I've come to the other side of that whole mess, and boy am I glad!

But here is what really got me excited during those months: flask, a framework for integrating Python code in webapps. Boy, did I discover a whole new world here! I had been trying, for quite a long while, to make the tools I've already built at work accessible to the other technicians. The main problem I was running into was all the different computers I needed to install it on.

I had what I call "Techassist" running just fine on my computer: I could query databases for our customer manager, Email server, spam filter and our rate limiter along with a few spreadsheets full of equipment with their respective IP addresses. What this allowed me to do was automate certain parts of my work, allowing me to enter data once and have it reflected in three different places. No typos, no 5-minute repetitive typing process.

I'd been using this program for months, but every time I tried installing it on another tech's PC, I ran into two problems: first, I needed to do it when they weren't on their computers. That's pretty rare. Second, their platforms were vastly different from mine. One tech is still running Windows XP for crying out loud! The others had different versions of Python running, QT failed installation for some reason, all sorts of little annoying things.

So one weekend I just asked myself: how long would it take to implement those features through a webapp?

Now maybe you're reading this and thinking I am taking the wrong direction. If you do, please let me know your reasons! This was actually a really hard choice for me to make. See, I love KDE. I love QT. I love applications that work, on or off-line. For those reasons, I've tried to make my programs work using those technologies as much as possible. But I realized an app like this is going to need to be on our internal, private network anyway because it's constantly running queries to our servers. If I did this through a web server, giving everyone with a web browser the same consistent experience, I save a lot of headaches while ensuring I have complete control over the only device that's going to be making these automated queries to so many different databases!

Plus, I'll be honest, I'm a visual guy, and I love Material Design. It's so easy for me to create what I want with CSS because I've used it forever, and this was a nice way to demonstrate what I could do in a way that was made more difficult (for me) with QT.

So I experimented with Django and NGINX for a few hours that weekend. I've always wanted to learn Django, but I quickly learned this would take several hours more than what I was ready for, just to get something simple working that day. Then I found Flask. It's similar, uses some of the same components (Jinja2 Templating language), and I had a basic webapp up in, I think, just under an hour? (Maybe I'm slow at learning from tutorials, but it was still faster!)

Fast-forward three weeks: I have been given my own virtual server hosted on our network at ATC Communications. I've got that server successfully talking to 2 different databases and we can import a service order by typing in one number. From that one number, we can now create a whole new user account just by reading data from one database and inserting it into the other! There are also actions for updating and removing accounts. I've implemented a search function that can find the device we're looking for by name and can launch a telnet session, separate browsing window or local management program based on the type of device!

I can add to any of these features or implement new modules without taking everyone else down or asking them to update. Everyone can get to this program and use it with no installation*! I set up a link where they can report errors directly to me. And, of course, it's all tracked with Git. I feel like Flask has enabled me to go crazy with all these tools I've had working but had no way to share! I'm so glad it's working and am looking forward to adding to it in the coming weeks.

*Okay, fine, you got me. If you want launching of what I defined as "radwin://" URL's to start a client-side batch script I wrote you'll need to download and run the custom registry file I created and the script I made. Let me tell you, that part is pretty sweet! You just click on a link and our manager program opens up with the username and password already entered and pointed at the right IP!