Skip to content

Commit

Permalink
ERCOT changed filenames from *.csv to *csv.zip
Browse files Browse the repository at this point in the history
  • Loading branch information
aschn committed Apr 14, 2014
1 parent 09ad941 commit 3b7ceec
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
7 changes: 6 additions & 1 deletion pyiso/ercot.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ def _request_report(self, report_type):
report_list_soup = BeautifulSoup(report_list_contents)

# find the endpoint to download
report_endpoint = None
for elt in report_list_soup.find_all('tr'):
label = elt.find(class_='labelOptional_ind')
if label:
if label.string[-3:] == 'csv':
if 'csv' in label.string:
report_endpoint = self.base_report_url + elt.a.attrs['href']
break

# test endpoint found
if not report_endpoint:
raise ValueError('ERCOT: No report available for %s, soup:\n%s' % (report_type, report_list_soup))

# read report from zip
r = requests.get(report_endpoint)
Expand Down
27 changes: 25 additions & 2 deletions tests/test_genmix.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging


class TestGenMix(TestCase):
class TestBaseGenMix(TestCase):
def setUp(self):
# set up expected values from base client
bc = BaseClient()
Expand Down Expand Up @@ -47,7 +47,9 @@ def _run_test(self, ba_name, **kwargs):

# return
return data



class TestISONEGenMix(TestBaseGenMix):
def test_isne_latest(self):
# basic test
data = self._run_test('ISONE', latest=True)
Expand All @@ -65,6 +67,8 @@ def test_isne_date_range(self):
timestamps = [d['timestamp'] for d in data]
self.assertGreater(len(set(timestamps)), 1)


class TestMISOGenMix(TestBaseGenMix):
def test_miso_latest(self):
# basic test
data = self._run_test('MISO', latest=True)
Expand All @@ -73,6 +77,8 @@ def test_miso_latest(self):
timestamps = [d['timestamp'] for d in data]
self.assertEqual(len(set(timestamps)), 1)


class TestSPPGenMix(TestBaseGenMix):
def test_spp_latest_hr(self):
# basic test
data = self._run_test('SPP', latest=True, market=self.MARKET_CHOICES.hourly)
Expand Down Expand Up @@ -128,6 +134,8 @@ def test_spp_yesterday_5min(self):
self.assertEqual(dp['market'], self.MARKET_CHOICES.fivemin)
self.assertEqual(dp['freq'], self.FREQUENCY_CHOICES.fivemin)


class TestBPAGenMix(TestBaseGenMix):
def test_bpa_latest(self):
# basic test
data = self._run_test('BPA', latest=True, market=self.MARKET_CHOICES.fivemin)
Expand Down Expand Up @@ -161,6 +169,8 @@ def test_bpa_date_range_farpast(self):
timestamps = [d['timestamp'] for d in data]
self.assertGreater(len(set(timestamps)), 1)


class TestCAISOGenMix(TestBaseGenMix):
def test_caiso_date_range(self):
# basic test
today = datetime.today().replace(tzinfo=pytz.utc)
Expand Down Expand Up @@ -222,6 +232,8 @@ def test_caiso_latest(self):
for expfuel in expected_fuels:
self.assertIn(expfuel, fuels)


class TestERCOTGenMix(TestBaseGenMix):
def test_ercot_latest(self):
# before min 32, will not have wind data
if datetime.now().minute >= 32:
Expand All @@ -247,7 +259,18 @@ def test_ercot_latest(self):
c = client_factory('ERCOT')
data = c.get_generation(latest=True)
self.assertEqual(len(data), 0)

def test_request_report(self):
# get data
c = client_factory('ERCOT')
result = c._request_report('gen_hrly')

# should be a list containing 1 dict
self.assertEqual(len(result), 1)
self.assertIn('SE_MW', result[0].keys())


class TestPJMGenMix(TestBaseGenMix):
def test_pjm_latest(self):
# basic test
data = self._run_test('PJM', latest=True)
Expand Down

0 comments on commit 3b7ceec

Please sign in to comment.