-
-
Save phreeza/da0d67aaf03d09791f7a to your computer and use it in GitHub Desktop.
Himawari-8 Wallpaper Bot: Fresh images of the whole Earth from space, every 10 minutes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
import datetime as dt | |
from datetime import timedelta | |
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)-timedelta(minutes=10)).strftime("%Y%m%d%H%M") | |
print timestamp | |
timestamp = timestamp[:-1] + '0' | |
print timestamp | |
timestamp = timestamp + '00' | |
print timestamp | |
filetype = ".jpg" | |
#img_url = lores + timestamp + filetype | |
img_url = hires + timestamp + filetype | |
print img_url | |
img_loc = dir + '/img/' + timestamp + filetype | |
urllib.urlretrieve(img_url, img_loc, reporthook=report) | |
size = 1100, 1100 | |
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 = (820, 100) | |
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
gsettings set org.gnome.desktop.background draw-background false && gsettings set org.gnome.desktop.background picture-uri file://$1 && gsettings set org.gnome.desktop.background draw-background true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment