Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ near-realtime picture of Earth.
```
usage: himawaripy [-h] [--version] [--auto-offset | -o OFFSET]
[-l {4,8,16,20}] [-d DEADLINE] [--save-battery]
[--output-dir OUTPUT_DIR] [--dont-change]
[--output-dir OUTPUT_DIR] [--dont-change] [--zoom]

set (near-realtime) picture of Earth as your desktop background

Expand All @@ -51,7 +51,7 @@ optional arguments:
--output-dir OUTPUT_DIR
directory to save the temporary background image
--dont-change don't change the wallpaper (just download it)

--zoom only use a random zoomed-in part of the picture
```

Most of the time himawaripy can accurately detect your timezone if you pass the flag `--auto-offset`, although you may
Expand Down
39 changes: 32 additions & 7 deletions himawaripy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import threading
import time
import subprocess
import random as rd
from math import sin, radians, floor

import appdirs
from PIL import Image
Expand Down Expand Up @@ -97,6 +99,8 @@ def parse_args():
default=appdirs.user_cache_dir(appname="himawaripy", appauthor=False))
parser.add_argument("--dont-change", action="store_true", dest="dont_change", default=False,
help="don't change the wallpaper (just download it)")
parser.add_argument("--zoom", action="store_true", dest="zoom", default=False,
help="use a random zoomed-in part of the picture")

args = parser.parse_args()

Expand Down Expand Up @@ -159,15 +163,36 @@ def thread_main(args):
if args.auto_offset or args.offset != 10:
print("Offset version: {} GMT.".format(strftime("%Y/%m/%d %H:%M:%S", requested_time)))

png = Image.new("RGB", (WIDTH * level, HEIGHT * level))

p = mp_dummy.Pool(level * level)
if args.zoom == False:
tilenum = level
offset_x = 0
offset_y = 0
copyrange_x = range(tilenum)
copyrange_y = range(tilenum)
else:
tilenum = 3 #crop a 3*3 out of the level*level image
#set boundry such that we don't look at complete darkness
h = requested_time.tm_hour
lower = floor(level/2+level/2*sin(radians(min(h/24*360+90,270))))
upper = floor(level/2+level/2*sin(radians(max(h/24*360-90,90))))
if lower == upper:
if h > 21:
offset_x = 0 #look at sunset(leftmost of image)
else:
offset_x = level-3 #look at sunrise(rightmost)
else:
offset_x = min(level-3, rd.randrange(lower,upper,1))
offset_y = rd.randrange(0,level-2,1)
copyrange_x = range(offset_x,offset_x+3)
copyrange_y = range(offset_y,offset_y+3)

png = Image.new("RGB", (WIDTH * tilenum, HEIGHT * tilenum))
p = mp_dummy.Pool(tilenum * tilenum)
print("Downloading tiles...")
res = p.map(download_chunk, it.product(range(level), range(level), (requested_time,), (args.level,)))

res = p.map(download_chunk, it.product(copyrange_x, copyrange_y, (requested_time,), (args.level,)))
for (x, y, tiledata) in res:
tile = Image.open(io.BytesIO(tiledata))
png.paste(tile, (WIDTH * x, HEIGHT * y, WIDTH * (x + 1), HEIGHT * (y + 1)))
png.paste(tile, (WIDTH * (x-offset_x), HEIGHT * (y-offset_y), WIDTH * ((x-offset_x) + 1), HEIGHT * ((y-offset_y) + 1)))

for file in iglob(path.join(args.output_dir, "himawari-*.png")):
os.remove(file)
Expand All @@ -178,7 +203,7 @@ def thread_main(args):
png.save(output_file, "PNG")

if not args.dont_change:
r = set_background(output_file)
r = set_background(output_file,args.zoom)
if not r:
sys.exit("Your desktop environment '{}' is not supported!\n".format(get_desktop_environment()))
else:
Expand Down
11 changes: 9 additions & 2 deletions himawaripy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from distutils.version import LooseVersion


def set_background(file_path):
def set_background(file_path,zoom):
de = get_desktop_environment()

if de == "mac":
Expand All @@ -25,8 +25,15 @@ def set_background(file_path):
if de == "unity":
subprocess.call(["gsettings", "set", "org.gnome.desktop.background", "draw-background", "false"])
subprocess.call(["gsettings", "set", "org.gnome.desktop.background", "picture-uri", "file://" + file_path])
subprocess.call(["gsettings", "set", "org.gnome.desktop.background", "picture-options", "scaled"])
if zoom:
pic_option = "zoom"
else:
pic_option = "scaled"
subprocess.call(["gsettings", "set", "org.gnome.desktop.background", "picture-options", pic_option])
subprocess.call(["gsettings", "set", "org.gnome.desktop.background", "primary-color", "#000000"])
#set as lock screen too
#subprocess.call(["gsettings", "set", "org.gnome.desktop.screensaver", "picture-uri", "file://" + file_path])
#subprocess.call(["gsettings", "set", "org.gnome.desktop.screensaver", "picture-options", "zoom"])
if de == "unity":
assert os.system('bash -c "gsettings set org.gnome.desktop.background draw-background true"') == 0
elif de == "mate":
Expand Down