-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathget_spa.py
44 lines (40 loc) · 1.42 KB
/
get_spa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#! /usr/env/python
"""
get spa c source from NREL for travis
"""
import requests
import os
import logging
# logger
logging.basicConfig(level=logging.DEBUG)
LOGGER = logging.getLogger(__file__)
# constants
SPAC_URL = r'https://midcdmz.nrel.gov/apps/download.pl' # spa.c source url
# register with NREL to download spa.c source
PAYLOAD = {
'name': 'uncertainty wrapper',
'country': 'US',
'company': 'SunPower',
'software': 'SPA'
}
SPAH_URL = r'http://midcdmz.nrel.gov/spa/spa.h' # spa.h source url
PVLIB_PATH = os.environ['PVLIB_PATH'] # path to PVLIB on travis
SPA_C_FILES = os.path.join(PVLIB_PATH, 'pvlib', 'spa_c_files')
if __name__ == "__main__":
# get spa.c source
LOGGER.debug('post payload to url: %s\n\tpayload:\n%s', SPAC_URL, PAYLOAD)
r = requests.post(SPAC_URL, data=PAYLOAD)
LOGGER.debug('post response: %r', r)
# save spa.c source to PVLIB/SPA_C_FILES folder
with open(os.path.join(SPA_C_FILES, 'spa.c'), 'wb') as f:
f.write(r.content)
LOGGER.debug('saved file: %r', f.name)
# get spa.c source
LOGGER.debug('get url: %s', SPAH_URL)
r = requests.get(SPAH_URL)
LOGGER.debug('get response: %r', r)
# save spa.c source to PVLIB/SPA_C_FILES folder
with open(os.path.join(SPA_C_FILES, 'spa.h'), 'wb') as f:
f.write(r.content)
LOGGER.debug('saved file: %r', f.name)
LOGGER.debug('exiting %s', __file__) # exit