In [1]:
import urllib # import the module urllib
In [2]:
url = "https://nomads.ncdc.noaa.gov/data/gfs4/201702/20170201/" # Link of the directory with the files to download
outpath = "." # Define the directory where you want to store the data
In [3]:
filename = "gfs_4_20170201_0000_000.grb2"
print url+filename # print the full link of the file
Download the file
In [8]:
urllib.urlretrieve(url+filename, outpath+filename) # arg1: link of the file, arg2: output path
Out[8]:
Create a list of integer
In [9]:
rng = range(1, 121)
print rng
Convert into a string and modify in the correct format
In [10]:
for r in rng:
print str(r).zfill(3)
In [11]:
basename = "gfs_4_20170201_0000_"
In [12]:
basename + str(r).zfill(3)+".grb2" # full filename
Out[12]:
In [14]:
filenames = [basename + str(r).zfill(3)+".grb2" for r in rng]
for filename in filenames:
print filename
Perform the download
In [ ]:
for filename in filenames:
print filename
urllib.urlretrieve(url+filename, outpath+filename)
In [ ]: