forked from boramalper/himawaripy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhimawaripy.py
executable file
·58 lines (40 loc) · 1.74 KB
/
himawaripy.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
#!/usr/bin/env python3
from io import BytesIO
from json import loads
from time import strptime, strftime
from subprocess import call
from os import makedirs
from os.path import expanduser, split
from urllib.request import urlopen
from PIL import Image
# Configuration
# =============
# Increases the quality and the size. Possible values: 4, 8, 16, 20
level = 4
# Path to the output file
output_file = expanduser("~/.himawari/himawari-latest.png")
# ==============================================================================
def main():
width = 550
height = 550
print("Updating...")
with urlopen("http://himawari8-dl.nict.go.jp/himawari8/img/D531106/latest.json") as latest_json:
latest = strptime(loads(latest_json.read().decode("utf-8"))["date"], "%Y-%m-%d %H:%M:%S")
print("Latest version: {} GMT\n".format(strftime("%Y/%m/%d/%H:%M:%S", latest)))
url_format = "http://himawari8.nict.go.jp/img/D531106/{}d/{}/{}_{}_{}.png"
png = Image.new('RGB', (width*level, height*level))
print("Downloading tiles: 0/{} completed".format(level*level), end="\r")
for x in range(level):
for y in range(level):
with urlopen(url_format.format(level, width, strftime("%Y/%m/%d/%H%M%S", latest), x, y)) as tile_w:
tiledata = tile_w.read()
tile = Image.open(BytesIO(tiledata))
png.paste(tile, (width*x, height*y, width*(x+1), height*(y+1)))
print("Downloading tiles: {}/{} completed".format(x*level + y + 1, level*level), end="\r")
print("\nDownloaded\n")
makedirs(split(output_file)[0], exist_ok=True)
png.save(output_file, "PNG")
call(["feh", "--bg-fill", "--no-fehbg", output_file])
print("Done!\n")
if __name__ == "__main__":
main()