- 积分
- 404
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2015-5-1
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
- # -*- coding:utf-8 -*-
- # @Author: DFY
- # @Time: 2020/4/3 11:06
- # @Email: 920745413@qq.com
- # @Desc: download data from mdfs
- import os
- import requests
- import datetime
- def download_diamond(start_time, source_path, out_path):
- """
- 下载micaps格式数据,保存文件为二进制格式
- :param start_time: 起报时间
- :param source_path: mdfs数据路径
- :param out_path: 文件输出路径
- :return: None
- """
- start_time_str = start_time.strftime("%Y%m%d%H")
- if not os.path.exists(out_path): os.makedirs(out_path)
- intervals = [i for i in range(0,73, 3)] + [i for i in range(78,241,6)]
- for interval in intervals:
- filename = f"{start_time_str[2:]}.{str(interval).zfill(3)}"
- out_filename = out_path + filename
- #10.xx.xx.146为mdfs数据源地址,需修改
- url = f"http://10.xx.xx.146:8080/DataService?requestType=getData&directory={source_path}&fileName={filename}"
- print(out_filename)
- re = requests.get(url)
- content = re.content
- for i in range(20):
- if content[i:i+4] == b"mdfs":
- content = content[i:]
- with open(out_filename, "wb") as fw:
- fw.write(content)
- break
- if __name__ == '__main__':
- start_time = datetime.datetime(2020, 4 , 2, 20)
- # source_path = "ECMWF_HR/TMP_2M" #EC地面两米温度
- source_path = "ECMWF_HR/WIND/850"
- out_path = f"../data/{start_time.strftime('%Y%m%d%H')}/{source_path}/"
- download_diamond(start_time, source_path, out_path)
|
|