diff --git a/README.md b/README.md index bb0f5cd..b7b1985 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ near-realtime picture of Earth. * GNOME 3 * Cinnamon 2.8.8 * KDE +* Deepin-Desktop ### Not Supported * any other desktop environments that are not mentioned above. @@ -46,8 +47,8 @@ If you use nitrogen for setting your wallpaper, you have to enter this in your You need a valid python3 installation including the python3-setuptools package: sudo apt install python3 - sudo apt install python3-setuptools - + sudo apt install python3-setuptools + ## Installation cd ~ @@ -91,7 +92,7 @@ You need a valid python3 installation including the python3-setuptools package: To change the wallpaper in KDE 5.7+, desktop widgets must be unlocked. If you dom't want to leave them unlocked, the pre-KDE 5.7 method can still be used. To unlock desktop widgets ([from the KDE userbase](https://userbase.kde.org/Plasma#Widgets)): -> Open the Desktop Toolbox or the Panel Toolbox or right click on the Desktop - if you see an item labeled Unlock Widgets then select that, and then proceed to add widgets to your Desktop or your Panel. +> Open the Desktop Toolbox or the Panel Toolbox or right click on the Desktop - if you see an item labeled Unlock Widgets then select that, and then proceed to add widgets to your Desktop or your Panel. #### Before KDE 5.7 > So the issue here is that KDE does not support changing the desktop wallpaper diff --git a/himawaripy/config.py b/himawaripy/config.py index 6792014..a21d91f 100644 --- a/himawaripy/config.py +++ b/himawaripy/config.py @@ -1,12 +1,15 @@ import appdirs # Increases the quality and the size. Possible values: 4, 8, 16, 20 -level = 4 +level = 8 -# Define a hourly offset or let the script calculate it depending on your timezone -# If auto_offset is True, then script will calculate your hour offset automatically depending on your location. +# Define a hourly offset or let the script calculate it depending on your +# timezone +# If auto_offset is True, then script will calculate your hour offset +# automatically depending on your location. # If hour_offset is greater than 0, then script will use it. -# If both of the variables are set different than their default values below, then script will raise an error. Here, +# If both of the variables are set different than their default values below, +# then script will raise an error. Here, # using the default values, script will put the realtime picture of Earth. auto_offset = True hour_offset = 0 diff --git a/himawaripy/himawaripy.py b/himawaripy/himawaripy.py index 8ed86c5..a4d22db 100755 --- a/himawaripy/himawaripy.py +++ b/himawaripy/himawaripy.py @@ -16,7 +16,7 @@ from pytz import timezone from dateutil.tz import tzlocal -from .config import level, output_dir, auto_offset, hour_offset , dl_deadline +from .config import level, output_dir, auto_offset, hour_offset, dl_deadline from .utils import set_background, get_desktop_environment counter = None @@ -52,14 +52,17 @@ def download_chunk(args): x, y, latest = args url_format = "http://himawari8.nict.go.jp/img/D531106/{}d/{}/{}_{}_{}.png" - url = url_format.format(level, width, strftime("%Y/%m/%d/%H%M%S", latest), x, y) + url = url_format.format(level, width, strftime("%Y/%m/%d/%H%M%S", latest), + x, y) - with urlopen(url , timeout=dl_timeout) as tile_w: + with urlopen(url, timeout=dl_timeout) as tile_w: tiledata = tile_w.read() with counter.get_lock(): counter.value += 1 - print("\rDownloading tiles: {}/{} completed".format(counter.value, level * level), end="", flush=True) + print("\rDownloading tiles: {}/{} completed".format(counter.value, + level * level), + end="", flush=True) return x, y, tiledata @@ -67,18 +70,24 @@ def main(): global counter if auto_offset and hour_offset: - exit("You can not set `auto_offset` to True and `hour_offset` to a value that is different than zero.") + exit("You can not set `auto_offset` to True and `hour_offset` to a \ + value that is different than zero.") elif hour_offset < 0: - exit("`hour_offset` must be greater than or equal to zero. I can't get future images of Earth for now.") + exit("`hour_offset` must be greater than or equal to zero. I can't \ + get future images of Earth for now.") 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") + 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".format(strftime("%Y/%m/%d %H:%M:%S", latest))) + print("Latest version: {} GMT".format(strftime("%Y/%m/%d %H:%M:%S", + latest))) if auto_offset or hour_offset > 0: requested_time = get_time_offset(latest) - print("Offset version: {} GMT".format(strftime("%Y/%m/%d %H:%M:%S", requested_time))) + print("Offset version: {} GMT".format(strftime("%Y/%m/%d %H:%M:%S", + requested_time))) else: requested_time = latest @@ -89,9 +98,11 @@ def main(): try: counter = Value("i", 0) p = Pool(cpu_count() * level) - print("Downloading tiles: 0/{} completed".format(level * level), end="", flush=True) + print("Downloading tiles: 0/{} completed".format(level * level), + end="", flush=True) try: - res = p.map(download_chunk, product(range(level), range(level), (requested_time,))) + res = p.map(download_chunk, product(range(level), range(level), + (requested_time,))) except TimeoutException: exit("\nTimeout while downloading tiles.") finally: # Make sure that we terminate proccess pool, whatever happens... @@ -100,18 +111,21 @@ def main(): for (x, y, tiledata) in res: tile = Image.open(BytesIO(tiledata)) - png.paste(tile, (width * x, height * y, width * (x + 1), height * (y + 1))) + png.paste(tile, (width * x, height * y, width * (x + 1), + height * (y + 1))) for file in iglob(join(output_dir, "himawari-*.png")): remove(file) - output_file = join(output_dir, strftime("himawari-%Y%m%dT%H%M%S.png", requested_time)) + output_file = join(output_dir, strftime("himawari-%Y%m%dT%H%M%S.png", + requested_time)) print("\nSaving to '%s'..." % (output_file)) makedirs(dirname(output_file), exist_ok=True) png.save(output_file, "PNG") if not set_background(output_file): - exit("Your desktop environment '{}' is not supported.".format(get_desktop_environment())) + exit("Your desktop environment '{}' is not supported." + .format(get_desktop_environment())) print("Done!") diff --git a/himawaripy/utils.py b/himawaripy/utils.py index 044c1d5..f0ff580 100644 --- a/himawaripy/utils.py +++ b/himawaripy/utils.py @@ -8,30 +8,43 @@ def set_background(file_path): de = get_desktop_environment() - if de in ["gnome", "unity", "cinnamon", "pantheon", "gnome-classic"]: - # Because of a bug and stupid design of gsettings, see http://askubuntu.com/a/418521/388226 + if de in ["gnome", "unity", "cinnamon", "pantheon", "gnome-classic", + "deepin"]: + # Because of a bug and stupid design of gsettings, + # see http://askubuntu.com/a/418521/388226 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"]) - subprocess.call(["gsettings", "set", "org.gnome.desktop.background", "primary-color", "#000000"]) + 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"]) + subprocess.call(["gsettings", "set", "org.gnome.desktop.background", + "primary-color", "#000000"]) elif de == "mate": - subprocess.call(["gsettings", "set", "org.mate.background", "picture-filename", file_path]) + subprocess.call(["gsettings", "set", "org.mate.background", + "picture-filename", file_path]) elif de == 'i3': - subprocess.call(['feh','--bg-max',file_path]) + subprocess.call(['feh', '--bg-max', file_path]) elif de == "xfce4": # Xfce4 displays to change the background of - displays = subprocess.getoutput('xfconf-query --channel xfce4-desktop --list | grep last-image').split() + displays = subprocess.getoutput('xfconf-query --channel xfce4-desktop \ + --list | grep last-image').split() for display in displays: - subprocess.call(["xfconf-query", "--channel", "xfce4-desktop", "--property", display, "--set", file_path]) + subprocess.call(["xfconf-query", "--channel", "xfce4-desktop", + "--property", display, "--set", file_path]) elif de == "lxde": - subprocess.call(["pcmanfm", "--set-wallpaper", file_path, "--wallpaper-mode=fit", ]) + subprocess.call(["pcmanfm", "--set-wallpaper", file_path, + "--wallpaper-mode=fit", ]) elif de == "mac": - subprocess.call(["osascript", "-e", 'tell application "System Events"\n' + subprocess.call(["osascript", "-e", 'tell application "System \ + Events"\n' 'set theDesktops to a reference to every desktop\n' 'repeat with aDesktop in theDesktops\n' - 'set the picture of aDesktop to \"' + file_path + '"\nend repeat\nend tell']) + 'set the picture of aDesktop to \"' + file_path + + '"\nend repeat\nend tell']) elif de == "kde": if plasma_version() > LooseVersion("5.7"): ''' Command per https://github.com/boramalper/himawaripy/issues/57 @@ -42,18 +55,23 @@ def set_background(file_path): script = 'var a = desktops();' \ 'for (i = 0; i < a.length; i++) {{' \ 'd = a[i];d.wallpaperPlugin = "org.kde.image";' \ - 'd.currentConfigGroup = Array("Wallpaper", "org.kde.image", "General");' \ + 'd.currentConfigGroup = Array("Wallpaper", \ + "org.kde.image", "General");' \ 'd.writeConfig("Image", "file://{}");' \ 'd.writeConfig("FillMode", 1);' \ 'd.writeConfig("Color", "#000");' \ '}}' try: - subprocess.check_output(["qdbus", "org.kde.plasmashell", "/PlasmaShell", - "org.kde.PlasmaShell.evaluateScript", script.format(file_path)]) + subprocess.check_output(["qdbus", "org.kde.plasmashell", + "/PlasmaShell", + "org.kde.PlasmaShell.evaluateScript", + script.format(file_path)]) except subprocess.CalledProcessError as e: if "Widgets are locked" in e.output.decode("utf-8"): - print("!! Cannot change the wallpaper while widgets are locked.") - print("!! Please unlock widgets to allow wallpaper changing.\n") + print("!! Cannot change the wallpaper while widgets \ + are locked.") + print("!! Please unlock widgets to allow wallpaper \ + changing.\n") else: print(e) else: @@ -64,8 +82,8 @@ def set_background(file_path): os.environ['DISPLAY'] = ':0' subprocess.call(["feh", "--bg-max", file_path]) elif has_program("nitrogen"): - print("\nCouldn't detect your desktop environment ('{}'), but you have " - "'nitrogen' installed so we will use it.".format(de)) + print("\nCouldn't detect your desktop environment ('{}'), \ + but you have 'nitrogen' installed so we will use it.".format(de)) os.environ["DISPLAY"] = ':0' subprocess.call(["nitrogen", "--restore"]) else: @@ -76,7 +94,7 @@ def set_background(file_path): # http://stackoverflow.com/a/21213358/4466589 def get_desktop_environment(): - # From http://stackoverflow.com/questions/2035657/what-is-my-current-desktop-environment + # From http://stackoverflow.com/questions/2035657 # and http://ubuntuforums.org/showthread.php?t=652320 # and http://ubuntuforums.org/showthread.php?t=652320 # and http://ubuntuforums.org/showthread.php?t=1139057 @@ -86,16 +104,22 @@ def get_desktop_environment(): return "mac" else: # Most likely either a POSIX system or something not much common desktop_session = os.environ.get("DESKTOP_SESSION") - if desktop_session is not None: # Easier to match if we don't have to deal with caracter cases + # Easier to match if we don't have to deal with caracter cases + if desktop_session is not None: desktop_session = desktop_session.lower() - if desktop_session in ["gnome", "unity", "cinnamon", "mate", "xfce4", "lxde", "fluxbox", - "blackbox", "openbox", "icewm", "jwm", "afterstep", "trinity", "kde", "pantheon", - "gnome-classic", "i3"]: + if desktop_session in ["gnome", "unity", "cinnamon", "mate", + "xfce4", "lxde", "fluxbox", "blackbox", + "openbox", "icewm", "jwm", "afterstep", + "trinity", "kde", "pantheon", + "gnome-classic", "i3", "deepin"]: return desktop_session - ## Special cases ## - # Canonical sets $DESKTOP_SESSION to Lubuntu rather than LXDE if using LXDE. - # There is no guarantee that they will not do the same with the other desktop environments. - elif "xfce" in desktop_session or desktop_session.startswith("xubuntu"): + # # Special cases ## + # Canonical sets $DESKTOP_SESSION to Lubuntu rather than LXDE if + # using LXDE. + # There is no guarantee that they will not do the same with the + # other desktop environments. + elif "xfce" in desktop_session \ + or desktop_session.startswith("xubuntu"): return "xfce4" elif desktop_session.startswith("ubuntu"): return "unity" @@ -122,7 +146,8 @@ def get_desktop_environment(): current_desktop = os.environ.get("XDG_CURRENT_DESKTOP") if current_desktop: current_desktop = current_desktop.lower() - if current_desktop in ["gnome", "unity", "kde", "gnome-classic", "mate"]: + if current_desktop in ["gnome", "unity", "kde", "gnome-classic", + "mate"]: return current_desktop # Special Cases @@ -144,7 +169,9 @@ def has_program(program): def plasma_version(): try: - output = subprocess.Popen(["plasmashell", "-v"], stdout=subprocess.PIPE).communicate()[0].decode("utf-8") + output = subprocess.Popen(["plasmashell", "-v"], + stdout=subprocess.PIPE).communicate()[0]\ + .decode("utf-8") print("\nRunning", output) version = re.match(r"plasmashell (.*)", output).group(1) return LooseVersion(version) diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index a1f991f..0573288 --- a/setup.py +++ b/setup.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + from setuptools import setup, find_packages diff --git a/systemd/himawaripy.service b/systemd/himawaripy.service index 5bcbfbf..103d45a 100644 --- a/systemd/himawaripy.service +++ b/systemd/himawaripy.service @@ -5,4 +5,4 @@ Description=Update desktop background with satellite imagery [Service] Type=oneshot -ExecStart= +ExecStart=/usr/bin/himawaripy