-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathweather.py
42 lines (33 loc) · 1.13 KB
/
weather.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/python
# coding: utf-8
# Weather forcast. This script uses OpenWeatherMap as data source.
# In order to use it, you need to create an account to obtain an key.
# You also need to install pyowm via the command : pip install pyowm
import pyowm
import time
from hanover_flipdot import display
from hanover_flipdot import fonts
API_KEY = "YOUR_API_KEY"
CITY = 'Mons'
COUNTRY = 'be'
display = display.Display("/dev/ttyUSB0", fonts.unscii_mcr, 128, 16, False, True)
owm = pyowm.OWM(API_KEY)
def current_weather():
observation = owm.weather_at_place('%s,%s'%(CITY, COUNTRY))
w = observation.get_weather()
display.erase_all()
display.write_text( "TMP: %s C"%(w.get_temperature('celsius')['temp']), line = 0)
display.write_text("HUM: %s%%"%w.get_humidity(), line = 8)
display.send()
def date_time():
display.erase_all()
for i in range(30):
display.write_text(time.strftime("%H:%M:%S"), column = 4)
display.write_text(time.strftime("%a %d %b %Y"), line = 8, column = 0)
display.send()
time.sleep(1)
while True:
current_weather()
time.sleep(20)
date_time()
time.sleep(1)