Last active
May 2, 2018 07:16
-
-
Save grisu48/4b1cf2fa2308d024f3b40d7955609cc6 to your computer and use it in GitHub Desktop.
Simple Python script to download current maps for my Garmin
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 python3 | |
| # -*- coding: utf-8 -*- | |
| # Python script for downloading the current GARMIN maps | |
| import os | |
| import requests | |
| import random | |
| import string | |
| def createTempFile(chars=8) : | |
| ''' | |
| Create and open a temp file | |
| ''' | |
| while True : | |
| ret = "" | |
| for i in range(chars) : ret += random.choice(string.ascii_letters) | |
| if not os.path.isfile(ret) : return ret | |
| def download(url, filename) : | |
| req = requests.get(url, stream=True) | |
| downFile = createTempFile() | |
| print("Downloading '" + url + "' to " + downFile + " ... ") | |
| try : | |
| with open(downFile, 'wb') as fd : | |
| for chunk in req.iter_content(100000): | |
| fd.write(chunk) | |
| fd.close() | |
| if os.path.isfile(filename) : os.remove(filename) | |
| os.rename(downFile, filename) | |
| finally : | |
| if os.path.isfile(downFile) : os.remove(downFile) | |
| if __name__ == "__main__" : | |
| # Main program part. | |
| # Add maps here, if you need them to be downloaded | |
| download('http://garmin.opentopomap.org/data/austria/austria_garmin.zip', 'austria_garmin.zip') | |
| download('http://garmin.opentopomap.org/data/alps/alps_garmin.zip', 'alps_garmin.zip') | |
| download('http://garmin.opentopomap.org/data/italy/italy_garmin.zip', 'italy_garmin.zip') | |
| download('http://garmin.opentopomap.org/data/germany/germany_garmin.zip', 'germany_garmin.zip') | |
| download('http://garmin.opentopomap.org/data/netherlands/netherlands_garmin.zip', 'netherlands_garmin.zip') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment