码迷,mamicode.com
首页 > 编程语言 > 详细

Python下载区域雷达拼图

时间:2015-12-23 22:37:35      阅读:518      评论:0      收藏:0      [点我收藏+]

标签:

下载某一天某区域全部的雷达拼图

 1 #!/usr/bin/env python3
 2 # -*- coding: utf-8 -*-
 3 quyu = {‘东北‘: ‘ANEC‘, ‘华北‘: ‘ANCN‘, ‘华东‘: ‘AECN‘, ‘华中‘: ‘ACCN‘,
 4         ‘华南‘: ‘ASCN‘, ‘西南‘: ‘ASWC‘, ‘西北‘: ‘ANWC‘, ‘长江‘: ‘ABCJ‘,
 5         ‘黄淮‘: ‘ABHH‘, ‘东南沿海‘: ‘ACES‘, ‘全国‘: ‘ACHN‘}
 6 
 7 
 8 def getRenderPic(year, month, day, region):
 9     ‘‘‘
10     下载某一天某区域全部的雷达拼图
11     调用: getRenderPic(2015, 12, 23, ‘华东‘)
12     ‘‘‘
13     import requests
14     import os
15     import time
16     now = time.localtime()
17     if (year, month, day) > (now[0], now[1], now[2]):
18         print(‘日期错误‘)
19         return
20     if region not in quyu:
21         print(‘区域错误,可用区域:‘)
22         print(quyu.keys())
23         return
24     date = str(year) + str(month).zfill(2) + str(day).zfill(2)
25     dirc = ‘/home/td/Desktop/radar/‘ + date + ‘/‘ + region  # 在此修改图片存储目录
26     try:
27         os.makedirs(dirc)
28     except:
29         pass
30     os.chdir(dirc)
31     if day == now[2]:
32         flag = True
33     for hh in range(0, 24):
34         for mm in range(0, 51, 10):
35             if flag:
36                 if (hh == now[3] and mm > now[4]) or hh > now[3]:
37                     return
38             time = str(hh).zfill(2) + str(mm).zfill(2)
39             url = ‘http://www.moc.cma.gov.cn/mocimg/radar/mosaic/‘ 40                 + quyu[region] + ‘/QREF/‘ + str(year) + ‘/‘ + str(month).zfill(2) 41                 + ‘/‘ + str(day).zfill(2) + ‘/‘ + quyu[region] + ‘.QREF000.‘ 42                 + date + ‘.‘ + time + ‘00.GIF‘
43             print(url)
44             pic = requests.get(url)
45             fp = open(date + time + ‘00‘ + ‘.gif‘, ‘wb‘)
46             fp.write(pic.content)
47             fp.close()
48 
49 if __name__ == ‘__main__‘:
50     getRenderPic(2015, 12, 23, ‘华东‘)

刚才试了一下今天的华东雷达,下载了一百多张图。

技术分享

Python下载区域雷达拼图

标签:

原文地址:http://www.cnblogs.com/aeropig/p/rader.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!