-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetData.py
executable file
·93 lines (73 loc) · 3.4 KB
/
getData.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/python3
import os
import shutil
import time
import datetime
from datetime import timedelta
from datetime import datetime
import requests
from bs4 import BeautifulSoup
import shutil
def listFD(url, ext=''):
page = requests.get(url).text
soup = BeautifulSoup(page, 'html.parser')
return [url + '/' + node.get('href') for node in soup.find_all('a') if node.get('href').endswith(ext)]
def listDD(url, ext=''):
page = requests.get(url).text
soup = BeautifulSoup(page, 'html.parser')
return [url + '/' + node.get('href') for node in soup.find_all('a')]
#url = 'https://mrms.ncep.noaa.gov/data/2D/MergedBaseReflectivityQC'
#localDirBase = '/home/disk/bob/impacts/raw/mrms/fillGaps/2DBaseReflQC'
#dateList = {'20230111':{'stime':'101412','etime':'161017'}}
#url = 'https://mrms.ncep.noaa.gov/data/2D/MergedReflectivityComposite'
#localDirBase = '/home/disk/bob/impacts/raw/mrms/fillGaps/2DReflComp'
#dateList = {'20230111':{'stime':'101437','etime':'162232'}}
url = 'https://mrms.ncep.noaa.gov/data/3DRefl'
localDirBase = '/home/disk/bob/impacts/raw/mrms/fillGaps/3DRefl'
dateList = {'20230111':{'stime':'101235','etime':'162232'}}
#url = 'https://mrms.ncep.noaa.gov/data/3DRhoHV'
#localDirBase = '/home/disk/bob/impacts/raw/mrms/fillGaps/3DRhoHV'
#dateList = {'20230111':{'stime':'101038','etime':'162534'}}
#url = 'https://mrms.ncep.noaa.gov/data/3DZdr'
#localDirBase = '/home/disk/bob/impacts/raw/mrms/fillGaps/3DZdr'
#dateList = {'20230111':{'stime':'101038','etime':'162534'}}
#url = 'https://mrms.ncep.noaa.gov/data/3DMergedBaseReflectivityQC'
#localDirBase = '/home/disk/bob/impacts/raw/mrms/fillGaps/Kdp'
#dateList = {'20230111':{'stime':'101038','etime':'162533'}}
#url = 'https://mrms.ncep.noaa.gov/data/3DMergedBaseReflectivityQC'
#localDirBase = '/home/disk/bob/impacts/raw/mrms/fillGaps/SPW'
#dateList = {'20230111':{'stime':'101038','etime':'163533'}}
ext = 'gz'
os.chdir(localDirBase)
for date in dateList.keys() :
s_datetime = date+dateList[date]['stime']
e_datetime = date+dateList[date]['etime']
if '3D' in url:
subdirs = listDD(url)
for sd in subdirs:
if 'Merged' in sd:
for file in listFD(sd, ext):
print(file)
if file.endswith('grib2.gz') and 'latest' not in file:
tmp = os.path.basename(file)
(base,ext) = os.path.splitext(tmp)
(base2,ext2) = os.path.splitext(base)
(junk,junk,junk,dateTimeStr) = base2.split('_')
(fdate,ftime) = dateTimeStr.split('-')
fdatetime = fdate+ftime
if fdatetime > s_datetime and fdatetime < e_datetime:
command = 'wget '+file
os.system(command)
elif '2D' in url:
for file in listFD(url, ext):
print(file)
if file.endswith('grib2.gz') and 'latest' not in file:
tmp = os.path.basename(file)
(base,ext) = os.path.splitext(tmp)
(base2,ext2) = os.path.splitext(base)
(junk,junk,junk,dateTimeStr) = base2.split('_')
(fdate,ftime) = dateTimeStr.split('-')
fdatetime = fdate+ftime
if fdatetime > s_datetime and fdatetime < e_datetime:
command = 'wget '+file
os.system(command)