- 积分
- 7958
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-9-19
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 忽忽儿 于 2018-9-18 17:52 编辑
想及时保存下雷达拼图,但是苦于网站保存期限过短,如果前一天有天气发生,可以用这个小程序把网站上的雷达拼图保存下来然后做动画,以便后期做分析哟~~
python初学者,是在前人的程序基础上修改的(参考的程序也是在家园里找的,但是2015年已经不能使用了,于是就在这个基础上改了一下),迫不及待想跟大家分享一下第一次用python编程成功的喜悦。程序还有很多不成熟或者啰嗦的地方,可以正常运行,如果有错误或修改意见望各位赐教!
源代码如下:
- # -*- coding: utf-8 -*-
- """
- wget radar png from 中国天气网
- @author: kaobozai
- """
- import os
- import time
- import pandas as pd
- import numpy as np
- # 输入前一天选定站点雷达图的url(主要包括中国各区域、北京、天津等)
- def get_img(year_in, month_in, day_in, station_info, path_to_save):
- hr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17",
- "18", "19", "20", "21", "22", "23"]
- mi = ["00", "06", "12", "18", "24", "30", "36", "42", "48", "54"]
- if station_info[1] == "z":
- image_path = "00000"
- if station_info[1] != "z":
- image_path = "00001"
- for hr_cell in hr:
- hr_str = hr_cell
- for mi_cell in mi:
- mi_str = mi_cell
- url_path = "http://pi.weather.com.cn/i/product/pic/l/sevp_aoc_rdcp_sldas_ebref_" + station_info + "_l88_pi_" + year_in + month_in + day_in + hr_str + mi_str + image_path + ".png"
- save_path = path_to_save + station_info + "/"
- os.system("wget -P " + save_path + " " + url_path)
- flag = year_in + month_in + day_in + hr_str + mi_str
- flag2 = "http://pi.weather.com.cn/i/product/pic/l/sevp_aoc_rdcp_sldas_ebref_" + station_info + "_l88_pi_" + year_in + month_in + day_in + hr_str + mi_str + image_path + ".png"
- print(flag)
- print(flag2)
- return 1
- # 调用当天日期并计算前一天,输出数据下载成功与否的结果并压缩文件
- yesterday = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime(time.time() - 86400)).split("-")
- yesterday1 = yesterday[0] + yesterday[1] + yesterday[2] # type: str
- path_to_save = "./radar_img/"+yesterday1+"/"
- record = []
- # 选择下载的雷达站点
- radar = pd.read_csv('radar_site.txt')
- datax = np.array(radar['site']) # 读取站点数据转化为nparray
- datay = np.array(radar['站名'])
- sitelistx = datax.tolist() # nparray转化为list
- sitelisty = datay.tolist()
- a = input("Enter a site:")
- for i in range(0, 11):
- if a == sitelisty[i]:
- print(sitelistx[i])
- station_info = sitelistx[i] # 站点选择完毕
- flag = get_img(yesterday[0], yesterday[1], yesterday[2], station_info, path_to_save)
- if flag == 1:
- record += [station_info + " !!!success!!!"]
- else:
- record += [station_info + "!!!fail!!!"]
- if os.system("tar -cvf radar_img_" + yesterday1 + ".tar.gz " + path_to_save)==0:
- record += ["tar file !!!success!!!"]
- else:
- record += ["tar file !!!fail!!!"]
- for cell in record:
- print(cell)
- print(time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime(time.time())))
复制代码
源代码文件和站点文本回复可见:
|
|