DerEddy

16x2 LCD

Jan 2nd, 2014
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. from Adafruit_CharLCD import Adafruit_CharLCD
  4. from subprocess import *
  5. from time import sleep, strftime, time
  6. from datetime import datetime
  7. from pywapi import get_weather_from_weather_com as pywapi
  8.  
  9. localcode = "GMXX1903"
  10.  
  11. lcd = Adafruit_CharLCD()
  12.  
  13. cmd = "ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1"
  14.  
  15. lcd.begin(16,1)
  16.  
  17. def run_cmd(cmd):
  18.         p = Popen(cmd, shell=True, stdout=PIPE)
  19.         output = p.communicate()[0]
  20.         return output
  21.  
  22. ipaddr = run_cmd(cmd)
  23. weather = pywapi(localcode)
  24. while 1:
  25.         lcd.clear()
  26.         lcd.message(datetime.now().strftime('%b %d  %H:%M:%S\n'))
  27.         lcd.message(" " + ipaddr)
  28.         sleep(2)
  29.  
  30.         lcd.clear()
  31.         lcd.message(datetime.now().strftime('%b %d  %H:%M:%S\n'))
  32.         unix = str(int(time()))
  33.         lcd.message(unix.center(16, "-"))
  34.         sleep(2)
  35.  
  36.         lcd.clear()
  37.         lcd.message(datetime.now().strftime('%b %d  %H:%M:%S\n'))
  38.         condition = weather["current_conditions"]["text"]
  39.         if condition.find(" ") > 0:
  40.                 #print condition
  41.                 #Example: Condition is "Mostly Cloudy"
  42.                 condition = condition.split()
  43.                 condition = condition[1]
  44.                 #print condition
  45.         weather_text = condition + " / " + weather["current_conditions"]["temperature"] + " C"
  46.         lcd.message(weather_text.center(16))
  47.         sleep(2)
  48.         while True:
  49.                 weather = pywapi(localcode)
  50.                 if len(weather) == 4:
  51.                         break
Advertisement
Add Comment
Please, Sign In to add comment