-
Notifications
You must be signed in to change notification settings - Fork 66
/
weather_landscape.py
59 lines (32 loc) · 1.31 KB
/
weather_landscape.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
from PIL import Image
from p_weather.openweathermap import OpenWeatherMap
from p_weather.sprites import Sprites
from p_weather.draw_weather import DrawWeather
import secrets
class WeatherLandscape:
TMP_DIR = "tmp"
OUT_FILENAME = "test_"
OUT_FILEEXT = ".bmp"
TEMPLATE_FILENAME = "p_weather/template.bmp"
SPRITES_DIR="p_weather/sprite"
DRAWOFFSET = 65
def __init__(self):
assert secrets.OWM_KEY != "000000000000000000", "Set OWM_KEY variable to your OpenWeather API key in secrets.py"
pass
def MakeImage(self)->Image:
owm = OpenWeatherMap(secrets.OWM_KEY,secrets.OWM_LAT,secrets.OWM_LON,self.TMP_DIR)
owm.FromAuto()
img = Image.open(self.TEMPLATE_FILENAME)
spr = Sprites(self.SPRITES_DIR,img)
art = DrawWeather(img,spr)
art.Draw(self.DRAWOFFSET,owm)
return img
def SaveImage(self)->str:
img = self.MakeImage()
placekey = OpenWeatherMap.MakePlaceKey(secrets.OWM_LAT,secrets.OWM_LON)
outfilepath = self.TmpFilePath(self.OUT_FILENAME+placekey+self.OUT_FILEEXT)
img.save(outfilepath)
return outfilepath
def TmpFilePath(self,filename):
return os.path.join(self.TMP_DIR,filename)