- Install requests:
pip install requests
- Set the
INTERVAL
- Create the output directory
mkdir maps
python main.py
Last active
October 15, 2015 16:34
-
-
Save achavez/80083a391af0ff8800d7 to your computer and use it in GitHub Desktop.
Download fire maps from USDA Forest Services on an interval
This file contains 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 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