Tuesday, January 12, 2016

Displaying python output with GeekTool

Living in Michigan, we are often hit with snow storms that cause us conditions to be too dangerous for driving to school.  These 'snowdays' are great, and every morning when the possibility of a snowday is present, I will often find myself checking our local news website to see if our schools name appears.  This often involves refreshing the website every few minutes (or even seconds! #fingercrossed) during the crucial minutes before I need to take a shower and get in the car or get back into bed.

So the other day when I was doing some web-scraping programming, the idea occurred to me to automate this process, so that I don't have to keep pressing refresh.  So I wrote a little python program that opened up the website, searched the html code for Kent county schools, and outputted the results.  This was the hard part, and one I'm not prepared to fully explain today.

Once I got the program printing what I wanted, I opened up GeekTool.  GeekTool is a mac program that allows you to display words, bits of code, website data, computer data, images, etc. on the background of your desktop.  You'll have to see for yourself various things it can do.

Anyhow, creating a shell geeklet with the following code will cause that python program to run and its output to show up on the computers desktop:
python ~/Documents/script/
In this case, was the name of the program I created -- but you could put the name of any python program there. Then one of the options you can set in GeekTool is how often this program refreshes itself, so I set mine for 60sec. The results:
For a half-hour this morning I sat and read the Bible, sipping coffee, and every 60secs or so looked up and watched as the list populated itself and grew automatically.  And, since you're reading this, eventually I did see my school's name pop up.  Unfortunately, the coffee had done its work and I couldn't fall back asleep.

By the way, the picture of the radar was also self refreshing -- every 300 seconds (5 minutes) GeekTools would fetch the image url, download the image and update my background.  

Apart from being able to be lazier than normal on a snowday morning, I will say there was an additional benefit to all this work.  By fetching it this way, I actually found out about my snowday 2 minutes faster than I would have otherwise (we receive text messages from remind), and my background was always a few schools ahead of the website the normal way through a browser and many schools ahead of perusing the website through their mobile app.

Next steps are to get my computer to check for my school, and automatically turn my alarm on/off based on whether the name shows up....    

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...