Random hacks
This is where I store bits and pieces of code that are useful, small, and hacked together. Everything posted on this particular page is released as public domain. Have fun with it.
Color Selector
A short python script useful for when you just want to get the hex or rgb values of a color. I've found this useful in several situations, such as programming or writing HTML.
#! /usr/bin/env python
import gtk
selector = gtk.ColorSelectionDialog("Color Selector")
selector.run()
The Weather Script
A script that grabs aviation text weather reports from the NOAA website. I use this and cron to put current weather information in my conky window. Be sure to change "KGGG" to an airport that you're actually close to.
#!/usr/bin/env python
import httplib
import urllib
import re
tafFinder = re.compile("(<PRE>)(.*)(</PRE>)", re.MULTILINE | re.DOTALL)
metarFinder = re.compile("(<FONT FACE=\"Monospace,Courier\">)(.*)(</FONT>)",
re.MULTILINE | re.DOTALL)
params = urllib.urlencode({'submit': 1, 'station_ids': "KGGG",
'chk_metars': "on", "chk_tafs": "on"})
headers = {"Content-type": "application/x-www-form-urlencoded",
"Accept": "text/html"}
connection = httplib.HTTPConnection("adds.aviationweather.gov")
connection.request("POST", "/metars/index.php", params, headers)
response = connection.getresponse()
tafFile = open("/tmp/taf.txt", "w")
metarFile = open("/tmp/metar.txt", "w")
if response.status == 200:
data = response.read()
taf = tafFinder.search(data)
tafFile.write(taf.group(2).strip())
metar = metarFinder.search(data)
metarFile.write(metar.group(2).strip())
else:
tafFile.write("Error retrieving TAF")
metarFile.write("Error retrieving METAR")
metarFile.close()
tafFile.close()
connection.close()