- 积分
- 404
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2015-5-1
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 Anonymous888 于 2018-7-1 10:40 编辑
使用requests模块下载fnl资料。以下源码只要输入邮箱及密码,更改下载时次及共多少个文件即可。
- # Author : dfy
- # Created : 21th June 2018
- #python version : 3.*
- import requests
- import datetime
- def builtSession():
- email = "***" #此处改为注册邮箱
- passwd = "***" #此处为登陆密码
- loginurl = "https://rda.ucar.edu/cgi-bin/login"
- params = {"email":email, "password":passwd, "action":"login"}
- sess = requests.session()
- sess.post(loginurl,data=params)
- return sess
- def download(sess, dt):
- g1 = datetime.datetime(1999,7,30,18)
- g2 = datetime.datetime(2007,12,6,12)
- if dt >= g2:
- suffix = "grib2"
- elif dt >= g1 and dt <g2:
- suffix = "grib1"
- else:
- raise StandardError("DateTime excess limit")
- url = "http://rda.ucar.edu/data/ds083.2"
- folder = "{}/{}/{}.{:0>2d}".format(suffix, dt.year, dt.year, dt.month)
- filename = "fnl_{}.{}".format(dt.strftime('%Y%m%d_%H_00'), suffix)
- fullurl = "/".join([url, folder, filename])
- r = sess.get(fullurl)
- with open(filename, "wb") as fw:
- fw.write(r.content)
- print(filename + " downloaded")
- if __name__ == '__main__':
- print("downloading...")
- s = builtSession()
- for i in range(12): #共下载多少个时次
- startdt = datetime.datetime(2018, 5, 16, 0) #开始时次
- interval = datetime.timedelta(hours = i * 6)
- dt =startdt + interval
- download(s,dt)
- print("download completed!")
|
评分
-
查看全部评分
|