Skip to content

Instantly share code, notes, and snippets.

@kuchaale
Forked from tristanwietsma/nexrad_composites.py
Created September 25, 2018 05:59
Show Gist options
  • Save kuchaale/7d6366770fdde29d2d54e0532b158558 to your computer and use it in GitHub Desktop.
Save kuchaale/7d6366770fdde29d2d54e0532b158558 to your computer and use it in GitHub Desktop.
Downloader for NEXRAD GeoTIFF composites
from sys import exit, argv
import datetime, zipfile
import requests
def dlhook(r, *args, **kwargs):
print('GET %s'%str(r.url))
base_url = "http://mesonet.agron.iastate.edu/request/gis/n0r2gtiff.php?dstr=%s"
def fetch(tme):
tm = tme.strftime('%Y%m%d%H%M')
url = base_url%tm
req = requests.get(url, hooks=dict(response=dlhook))
with open('%s.zip'%tm, 'w') as myzip:
myzip.write(req.content)
def fetch_range(start, stop):
while start < stop:
fetch(start)
start += datetime.timedelta(seconds=5*60)
if __name__ == '__main__':
begin = datetime.datetime(2013, 1, 1)
end = datetime.datetime(2013, 1, 2)
fetch_range(begin, end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment