Skip to content

Instantly share code, notes, and snippets.

@achavez
Last active October 15, 2015 16:34
Show Gist options
  • Save achavez/80083a391af0ff8800d7 to your computer and use it in GitHub Desktop.
Save achavez/80083a391af0ff8800d7 to your computer and use it in GitHub Desktop.
Download fire maps from USDA Forest Services on an interval
  1. Install requests: pip install requests
  2. Set the INTERVAL
  3. Create the output directory mkdir maps
  4. python main.py
import time
import requests
INTERVAL = 15 * 60
FILE_URL = 'http://activefiremaps.fs.fed.us/data/kml/conus_latest_modis.kml'
DESTINATION_FOLDER = 'maps'
def download_file():
r = requests.get(FILE_URL)
if r.status_code == 200:
file_name = '%s/%s.kml' % (DESTINATION_FOLDER, int(time.time()))
with open(file_name, 'wb') as f:
for chunk in r.iter_content(1024):
f.write(chunk)
print('[%s] - Saved updated map to %s.' % (int(time.time()),
file_name))
else:
print('[%s] - %s error downloading the file.' % (
int(time.time()),
r.status_code)
)
if __name__ == "__main__":
download_file()
while True:
print('[%s] - Sleeping for %s minutes.' % (
int(time.time()),
INTERVAL // 60)
)
time.sleep(INTERVAL)
download_file()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment