-
Notifications
You must be signed in to change notification settings - Fork 2
/
auto_radar_download.py
57 lines (49 loc) · 1.93 KB
/
auto_radar_download.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from tqdm import tqdm
import requests
import time
import os
BaseUrl_1 = "http://61.56.11.42/nidsB/images/QPESUMSgoogle/cref2d_rad/COMPREF."
"yyyymmdd.hhmm"
BaseUrl_2 = ".LST.png"
archfiles = os.listdir(".")
timestart = time.time()-86400*7
time_st = time.struct_time(time.localtime(timestart))
timestart = timestart - ((time_st[4]%10)*60 + time_st[5])
while timestart<time.time()-600:
timestring = time.strftime("%Y%m%d.%H%M",time.localtime(timestart))
url = BaseUrl_1+ timestring + BaseUrl_2
filename = time.strftime("%Y%m%d_%H%M",time.localtime(timestart))+ ".png"
print "Finding " + filename
if (filename not in archfiles):
print("Downloading %s as %s \r\n" % (url,filename))
response = requests.get(url, stream=True)
with open(filename , "wb") as handle:
for data in tqdm(response.iter_content(1024*100)):
handle.write(data)
pass
timestart = timestart +600
pass
print "finish downloading last 7 days data"
t = time.time()
time_st = time.struct_time(time.localtime(t))
t = t - ((time_st[4]%10)*60 + time_st[5])
t = t + 540
print "Sleep until" + time.strftime(" %Y%m%d %H:%M:%S", time.localtime(t))
print "Sleep" + str(t -time.time())
time.sleep(t -time.time())
while 1:
t = time.time()
time_st = time.struct_time(time.localtime(t))
t = t - ((time_st[4]%10)*60 + time_st[5])
timestring = time.strftime("%Y%m%d.%H%M", time.localtime(t))
url = BaseUrl_1+ timestring + BaseUrl_2
filename = time.strftime("%Y%m%d_%H%M", time.localtime(t))
print("Downloading %s as %s \r\n" % (url,filename))
response = requests.get(url, stream=True)
with open(filename+ ".png" , "wb") as handle:
for data in tqdm(response.iter_content(1024*100)):
handle.write(data)
t = t + 540 +600
print "Sleep until" + time.strftime(" %Y%m%d %H:%M:%S", time.localtime(t))
print "Sleep" + str(t -time.time())
time.sleep(t -time.time())