Skip to content

Instantly share code, notes, and snippets.

@aahoo
Last active October 26, 2023 22:36
Show Gist options
  • Save aahoo/b4aaeb179b51b69e342c5e324e305155 to your computer and use it in GitHub Desktop.
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
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!'
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