himawari8图片下载改进版

Posted in 2017-3-23 11:42 | Category: Python | Tags: earth himawari8 python

第一版下载图片后设为壁纸,四周都是黑黑的不好看, 所以结合本地壁纸将两张图片进行合成

只要计算一下要缩减的大小与要放置的位置

我的方法是:打开 gimp,合成两张图片,记下缩减的大小(214,214)与位置(160,160)

每次只要运行一下

python himawari8.py

源码

from PIL import Image, ImageOps, ImageDraw
from io import BytesIO
from urllib.request import Request, urlopen
from datetime import datetime, timedelta
import json

SCALE = 2
WIDTH = 1368
HEIGHT = 768


def get_info():
    url = "http://himawari8-dl.nict.go.jp/himawari8/img/D531106/latest.json"
    request = Request(url)
    response = urlopen(request, timeout=10)
    return json.loads(response.read())


def download():
    png = Image.new('RGB', (550 * SCALE, 550 * SCALE))
    # desktop = Image.new('RGB', (WIDTH, HEIGHT))
    desktop = Image.open('/home/jianglin/Pictures/308556.png')
    url_format = 'http://himawari8-dl.nict.go.jp/himawari8/img/D531106/{}d/{}/{}_{}_{}.png'
    info = get_info()
    # date = datetime.strptime(info['date'], '%Y-%m-%d %H:%M:%S') + timedelta(
    #     hours=-8)
    date …

下载Himawari8拍摄的实时地球图片

Posted in 2017-3-22 22:10 | Category: Python | Tags: earth himawari8 python

设置壁纸

feh --bg-scale /tmp/earth.png

设置桌面大小,及图片放大倍数

SCALE = 4
WIDTH = 1368
HEIGHT = 768

直接给出源码

from PIL import Image
from io import BytesIO
from urllib.request import Request, urlopen
from datetime import datetime
import json

SCALE = 4
WIDTH = 1368
HEIGHT = 768


def get_info():
    url = "http://himawari8-dl.nict.go.jp/himawari8/img/D531106/latest.json"
    request = Request(url)
    response = urlopen(request, timeout=10)
    return json.loads(response.read())


def download():
    png = Image.new('RGB', (550 * SCALE, 550 * SCALE))
    desktop = Image.new('RGB', (WIDTH, HEIGHT))
    url_format = 'http://himawari8-dl.nict.go.jp/himawari8/img/D531106/{}d/{}/{}_{}_{}.png'
    info = get_info()
    date = datetime.strptime(info['date'], '%Y-%m-%d %H:%M:%S')
    for x in range(SCALE):
        for y in range(SCALE):
            url = url_format.format(SCALE, 550,
                                    date.strftime("%Y/%m …