使用python获取实时卫星云图

来源:互联网 发布:远程数据采集系统 编辑:程序博客网 时间:2024/05/01 11:51

【转载】http://blog.leniy.org/python-satellite-images.html

#coding:utf-8#加载模块import urllib2import datetime#时间列表生成函数def time_list(time_start,time_end,half_hour):    #获取14位的时间列表,形如20130426080000    t = []    time_temp = time_start    while time_temp <= time_end:        a1 = str(time_temp)[0:4]        a2 = str(time_temp)[5:7]        a3 = str(time_temp)[8:10]        a4 = str(time_temp)[11:13]        a5 = str(time_temp)[14:16]        a6 = str(time_temp)[17:19]        t.append(a1+a2+a3+a4+a5+a6)        time_temp += half_hour    return t#下载卫星云图文件函数def download(time_list):    #下载卫星云图    for the_time in time_list:        url = "http://i.weather.com.cn/i/product/pic/l/sevp_nsmc_wxcl_asc_e99_achn_lno_py_" + the_time + '000.jpg'        socket = urllib2.urlopen(url)        data = socket.read()        if data[0] != '<':            #如果数据开头是<符号,说明返回的不是图片数据而是html数据            #也就是说,网站的404返回页面。            #此时本图片不存在,跳过不下载            #只有数据开头不是<符号,才执行后续下载            download_path = './img/' + the_time + '.jpg'            with open(download_path,'wb') as jpg:                jpg.write(data)            socket.close()#执行#下载xxxx.xx.xx到xxxx.xx.xx的图片time_start = datetime.datetime(2015,7,13,8,00,0)time_end = datetime.datetime(2015,7,14,8,00,0)half_hour = datetime.timedelta(minutes=30)download(time_list(time_start,time_end,half_hour))#生成gif'''不会弄=  = 网上找一下吧。。。参考一下这个? http://bbs.chinaunix.net/thread-1857467-1-1.html'''

这里写图片描述
这里写图片描述
这里写图片描述

0 0