Created
February 17, 2011 21:20
-
-
Save elidickinson/832730 to your computer and use it in GitHub Desktop.
Send weather updates to your HP Printer LCD dispaly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import pywapi # http://code.google.com/p/python-weather-api/ | |
import telnetlib | |
import sys | |
if len(sys.argv) != 3: | |
print "USAGE: python print_weather.py <ZIPCODE> <PRINTER_IP>" | |
exit() | |
location_id = sys.argv[1] | |
printer_host = sys.argv[2] | |
forecast = pywapi.get_weather_from_google(location_id) | |
weather_str = ("%sF %s. %s:%s" % (forecast['current_conditions']['temp_f'], | |
forecast['current_conditions']['condition'], | |
forecast['forecasts'][0]['day_of_week'], | |
forecast['forecasts'][0]['condition'])) | |
weather_str = "\x1B%%-12345X@PJL RDYMSG DISPLAY = \"%s\"\r\n\x1B%%-12345X\r\n" % (weather_str) | |
tn = telnetlib.Telnet(printer_host,9100) | |
tn.write(weather_str.encode('latin-1')) # encode to workaround this bug http://bugs.python.org/issue1772794 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment