Skip to content

Instantly share code, notes, and snippets.

@jarmitage
Last active March 5, 2018 09:21
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jarmitage/5042bfe20aa54b3d8dc8 to your computer and use it in GitHub Desktop.
Save jarmitage/5042bfe20aa54b3d8dc8 to your computer and use it in GitHub Desktop.
Himawari-8 Wallpaper Bot: Fresh images of the whole Earth from space, every 10 minutes
import urllib
import datetime as dt
import pytz
from PIL import Image
import numpy as np
import subprocess
import socket
import os
dir = '/FULL/PATH/TO/SCRIPT/DIR'
def download_latest_image():
tz=pytz.timezone('Atlantic/Cape_Verde')
#hires = "http://rammb.cira.colostate.edu/ramsdis/online/images/hi_res/himawari-8/full_disk_ahi_true_color/full_disk_ahi_true_color_"
lores = "http://rammb.cira.colostate.edu/ramsdis/online/images/himawari-8/full_disk_ahi_true_color/full_disk_ahi_true_color_"
timestamp = dt.datetime.now(tz).strftime("%Y%m%d%H")
mins = int(dt.datetime.now(tz).strftime("%M")[:1])
#todo: fix timestamp bug
if mins != 0:
mins = mins - 1
timestamp = timestamp + str(mins) + '000'
filetype = ".jpg"
img_url = lores + timestamp + filetype
#img_url = hires + timestamp + filetype
img_loc = dir + '/img/' + timestamp + filetype
urllib.urlretrieve(img_url, img_loc, reporthook=report)
size = 1000, 1000
im = Image.open(dir + '/img/' + timestamp + filetype).convert('RGB')
im = im.resize(size, Image.ANTIALIAS)
logo_dims = (180, 80)
logo_box = (0, size[0] - logo_dims[1], logo_dims[0], size[1])
logo = np.array(im.crop(logo_box))
logo[..., ...][...] = (0, 0, 0)
logo_edited = Image.fromarray(logo)
im.paste(logo_edited, logo_box)
border = (1000, 200)
new_size = (size[0] + border[0], size[0] + border[1])
new_im = Image.new('RGB', new_size)
paste_pos = (border[0]/2, border[1]/2, new_size[0] - (border[0]/2), new_size[1] - (border[1]/2))
new_im.paste(im, paste_pos)
new_im_name = timestamp + filetype
new_im.save(dir + '/img/' + new_im_name)
cmd = 'sh ' + dir + '/set_desktop.sh ' + dir + '/img/' + new_im_name
subprocess.call(cmd, shell=True)
for file in os.listdir(dir + '/img/'):
if file != timestamp + filetype:
os.remove(dir + '/img/' + file)
def report(count, blockSize, totalSize):
percent = int(count * blockSize * 100 / totalSize)
print("\r%d%%" % percent + ' complete')
def is_connected():
try:
host = socket.gethostbyname('www.google.com')
s = socket.create_connection((host, 80), 2)
return True
except:
pass
return False
if is_connected():
download_latest_image()
#!/bin/bash
sqlite3 ~/Library/Application\ Support/Dock/desktoppicture.db "update data set value = '$1'" && killall Dock
@raed667
Copy link

raed667 commented Dec 31, 2015

I made this work on Linux Mint (Cinnamon) by changing just this line

    cmd = 'gsettings set org.cinnamon.desktop.background picture-uri "file:///' + dir + '/img/' + new_im_name+'"'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment