Skip to content

Commit

Permalink
Merge pull request #1 from sgnn7/master
Browse files Browse the repository at this point in the history
General cleanup
  • Loading branch information
boramalper committed Feb 4, 2016
2 parents 722c1b7 + c707a3a commit b0652a5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ time to download the tiles.
vi himawaripy.py

# test whether it's working
python3 himawaripy.py
./himawaripy.py

# set up a cronjob
crontab -e
# Add the line:
# */10 * * * * python3 /home/USERNAME/himawaripy/himawaripy.py
# */10 * * * * /home/USERNAME/himawaripy/himawaripy.py

## Example
![Earth, as 2016/02/04/13:30:00 GMT](http://i.imgur.com/4XA6WaM.jpg)
Expand Down
24 changes: 12 additions & 12 deletions himawaripy.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python3

from json import loads
from io import BytesIO
from urllib.request import urlopen
from json import loads
from time import strptime, strftime
from os import system
from os.path import expanduser
from urllib.request import urlopen

from PIL import Image

Expand All @@ -15,7 +15,7 @@
# =============

# Increases the quality and the size. Possible values: 4, 8, 16, 20
level = 4
level = 4

# ==============================================================================

Expand All @@ -26,6 +26,7 @@ def main():
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"
Expand All @@ -37,21 +38,21 @@ def main():
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))

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")

png.save(expanduser("~/.himawari-latest.png"), "PNG")
output_file = expanduser("~/.himawari-latest.png")
png.save(output_file, "PNG")

de = get_desktop_environment()
if de in ["gnome", "unity", "cinnamon"]:
if de in ["gnome", "unity", "cinnamon"]:
# Because of a bug and stupid design of gsettings, see http://askubuntu.com/a/418521/388226
system("gsettings set org.gnome.desktop.background draw-background false \
&& gsettings set org.gnome.desktop.background picture-uri file://"
+ expanduser("~/.himawari-latest.png") +
&& gsettings set org.gnome.desktop.background picture-uri file://" + output_file +
" && gsettings set org.gnome.desktop.background picture-options scaled")
elif de == "mate":
system("gconftool-2 -type string -set /desktop/gnome/background/picture_filename \"{}\"".format(expanduser("~/.himawari-latest.png")))
Expand All @@ -61,7 +62,6 @@ def main():
exit("Your desktop environment '{}' is not supported.".format(de))

print("Done!\n")

if __name__ == "__main__":
main()

0 comments on commit b0652a5

Please sign in to comment.