Skip to content

Commit 7b36213

Browse files
committed
Changed timetemp to display with openweathermap
1 parent 3e7be0b commit 7b36213

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

Adafruit_Thermal.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,11 @@ def printBitmap(self, w, h, bitmap, LaaT=False):
548548
# the Imaging Library to perform such operations before
549549
# passing the result to this function.
550550
def printImage(self, image_file, LaaT=False):
551-
from PIL import Image
552-
image = Image.open(image_file)
551+
image = image_file
552+
553+
if isinstance(image_file, str):
554+
image = Image.open(image_file)
555+
553556
if image.mode != '1':
554557
image = image.convert('1')
555558

15.2 KB
Binary file not shown.

timetemp.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,31 @@
1515

1616
from __future__ import print_function
1717
from Adafruit_Thermal import *
18-
import time, urllib, json
18+
import time, urllib.request, json
1919
from PIL import Image, ImageDraw
2020

21-
API_KEY = "YOUR_API_KEY"
21+
API_KEY = "YOUR_OPEN_WEATHER_API_KEY"
2222

23-
LAT = "40.726019"
24-
LONG = "-74.00536"
23+
cityName = "YOUR_CITY_NAME"
2524

2625
# Fetch weather data from DarkSky, parse resulting JSON
27-
url = "https://api.darksky.net/forecast/"+API_KEY+"/"+LAT+","+LONG+"?exclude=[alerts,minutely,hourly,flags]&units=us"
28-
response = urllib.urlopen(url)
26+
url = f"http://api.openweathermap.org/data/2.5/weather?q={cityName}&appid={API_KEY}"
27+
response = urllib.request.urlopen(url)
2928
data = json.loads(response.read())
30-
29+
print(data)
3130
# Extract values relating to current temperature, humidity, wind
3231

33-
temperature = int(data['currently']['temperature'])
34-
humidity = int(data['currently']['humidity'] * 100);
35-
windSpeed = int(data['currently']['windSpeed'])
36-
windDir = data['currently']['windBearing']
32+
temperature = (int(data['main']['temp']) - 273.15) * 9/5 + 32
33+
humidity = int(data['main']['humidity'] * 100);
34+
windSpeed = int(data['wind']['speed'])
35+
windDir = data['wind']['deg']
3736
windUnits = "mph"
3837

3938
# print(temperature)
40-
# print(humidity)
41-
# print(windSpeed)
42-
# print(windDir)
43-
# print(windUnits)
39+
# print(humidity)
40+
# print(windSpeed)
41+
# print(windDir)
42+
# print(windUnits)
4443

4544
# Although the Python Imaging Library does have nice font support,
4645
# I opted here to use a raster bitmap for all of the glyphs instead.
@@ -137,7 +136,7 @@ def numWidth(str, list):
137136
if windSpeed > 0:
138137
for winDirNum in range(len(DirAngle) - 1):
139138
if windDir < DirAngle[winDirNum]: break
140-
winDirNum+=1
139+
winDirNum+=1
141140
w = Humidity.size[0] + 5 + numWidth(s, HumiDigit)
142141
w2 = Wind.size[0] + 5 + numWidth(s2, HumiDigit)
143142
if windSpeed > 0:

0 commit comments

Comments
 (0)