Last active
October 26, 2023 22:36
-
-
Save aahoo/b4aaeb179b51b69e342c5e324e305155 to your computer and use it in GitHub Desktop.
Automatically download energyplus weather data files (epw and ddy), 2 versions python 2 and 3
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 json | |
import re | |
import urllib2 | |
path_to_save = '' # create a directory and write the name of directory here | |
data_file = urllib2.urlopen('https://github.com/NREL/EnergyPlus/raw/develop/weather/master.geojson') | |
data = json.load(data_file) | |
# or you can download master.geojson and run the below code instead of downloading from the net | |
# with open('master.geojson') as data_file: | |
# data = json.load(data_file) | |
for location in data['features']: | |
for file_type in ['epw', 'ddy']: | |
match = re.search(r'href=[\'"]?([^\'" >]+)', location['properties'][file_type]) | |
if match: | |
url = match.group(1) | |
name = url[url.rfind('/') + 1:] | |
print name | |
req = urllib2.Request(url, headers={'User-Agent' : "Magic Browser"}) | |
con = urllib2.urlopen( req ) | |
with open(path_to_save + name, 'wb') as f: | |
f.write(con.read()) | |
print 'done!' |
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 json | |
import re | |
from urllib.request import Request, urlopen | |
path_to_save = '' # create a directory and write the name of directory here | |
response = urlopen('https://github.com/NREL/EnergyPlus/raw/develop/weather/master.geojson') | |
data = json.loads(response.read().decode('utf8')) | |
count = 0 | |
for location in data['features']: | |
for file_type in ['epw', 'ddy']: | |
match = re.search(r'href=[\'"]?([^\'" >]+)', location['properties'][file_type]) | |
if match: | |
url = match.group(1) | |
name = url[url.rfind('/') + 1:] | |
count += 1 | |
print(count, ':', name, '\t') | |
response = Request(url, headers={'User-Agent' : "Magic Browser"}) | |
with open(path_to_save + name, 'wb') as f: | |
f.write(urlopen(response).read()) | |
print('done!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment