Created
February 10, 2011 19:54
-
-
Save sansumbrella/821206 to your computer and use it in GitHub Desktop.
Downloads the current day's precipitation shapefile from NOAA.
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
#!/usr/bin/env python | |
# encoding: utf-8 | |
import sys | |
import os | |
import commands | |
from datetime import date | |
def main(): | |
downloadDaysData( date.today() ) | |
def downloadDaysData( desiredDate ): | |
base_url = "http://water.weather.gov/precip/p_download_new/%i/%02i/%02i/" % ( desiredDate.year, desiredDate.month, desiredDate.day ) | |
filebase = "nws_precip_1day_observed_shape_%i%02i%02i" % ( desiredDate.year, desiredDate.month, desiredDate.day ) | |
pngname = "conus_precip-composite_hi_res_%i%02i%02i.tar.gz" % ( desiredDate.year, desiredDate.month, desiredDate.day ) | |
filename = filebase + ".tar.gz" | |
url = base_url + filename | |
pngurl = base_url + pngname | |
if( os.path.exists(filebase) ): | |
print "Already extracted today's file" | |
else: | |
print "Downloading %s" % url | |
out = commands.getoutput( "curl %s -O" % url ) | |
placeDownloadInFolder( filename, filebase ) | |
print "Downloading preview image" | |
png = commands.getoutput( "curl %s -O" % pngurl ) | |
placeDownloadInFolder( pngname, filebase ) | |
print "All done" | |
def placeDownloadInFolder( filename, folder ): | |
print "Extracting %s to %s" % ( filename, folder ) | |
if( not os.path.exists( folder ) ): | |
commands.getoutput( "mkdir %s" % folder ) | |
commands.getoutput( "mv %s %s" % ( filename, folder ) ) | |
commands.getoutput( "cd %s && tar -zxvf %s && rm %s" % ( folder, filename, filename ) ) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment