Skip to content

Instantly share code, notes, and snippets.

@elidickinson
Created February 17, 2011 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elidickinson/832730 to your computer and use it in GitHub Desktop.
Save elidickinson/832730 to your computer and use it in GitHub Desktop.
Send weather updates to your HP Printer LCD dispaly
#!/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