Last active
August 29, 2015 14:14
-
-
Save guziy/05325a1c39c3e05eada5 to your computer and use it in GitHub Desktop.
Some script I've used to download snow extent data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import re | |
import os | |
url = "http://www.globsnow.info/se/archive_v2.1/{}/D4SC/" | |
start_year = 2003 | |
end_year = 2003 | |
for year in range(start_year, end_year + 1): | |
year_url = url.format(year) | |
# get the html of the directory listing | |
x = urllib2.urlopen(year_url).read() | |
# Get all words starting with GlobSnow and ending with .nc.gz, ? - means non-greedy | |
fnames = re.findall(r"GlobSnow.*?\.nc\.gz", x) | |
print len(fnames) | |
fnames = set(fnames) # Eliminate duplicates | |
print len(fnames) | |
for fname in fnames: | |
if os.path.isfile(fname): # No need to download the same file several times | |
continue | |
with open(fname, "w") as f: | |
flink = os.path.join(year_url, fname) | |
print "Downloading {} ....".format(flink) | |
f.write(urllib2.urlopen(flink).read()) | |
print "Downloaded data for year {}".format(year) | |
print "All downloads finished successfully" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment