Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit e0e8e9c
Merge: 38cf328 b7a8254
Author: Colin Catlin <[email protected]>
Date:   Fri Feb 2 11:37:09 2024 -0600

    Merge pull request winedarksea#231 from winedarksea/dev

    docs analytics id fix

commit 38cf328
Merge: 3e6baff 3b3d0b0
Author: Colin Catlin <[email protected]>
Date:   Tue Jan 30 00:08:40 2024 -0600

    Merge pull request winedarksea#230 from winedarksea/dev

    0.6.10

commit 3e6baff
Merge: c23c244 c40093a
Author: Colin Catlin <[email protected]>
Date:   Mon Jan 22 07:43:08 2024 -0600

    Merge pull request winedarksea#227 from winedarksea/dev

    0.6.9

commit c23c244
Merge: 4e4f6bd ec6860c
Author: Colin Catlin <[email protected]>
Date:   Thu Jan 18 09:10:50 2024 -0600

    Merge pull request winedarksea#226 from winedarksea/dev

    0.6.8
  • Loading branch information
lewuyou committed Feb 23, 2024
1 parent f08512f commit 99c25cd
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions autots/datasets/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,92 @@ def load_live_daily(
except Exception as e:
print(f"eia download failed with error {repr(e)}")

if eia_key is not None and eia_respondents is not None:
api_url = 'https://api.eia.gov/v2/electricity/rto/daily-region-data/data/' # ?api_key={eia-key}
for respond in eia_respondents:
try:
params = {
"frequency": "daily",
"data": ["value"],
"facets": {
"type": [
"D"
],
"respondent": [
respond
],
"timezone": [
"Eastern"
]
},
"start": None, # "start": "2018-06-30",
"end": None, # "end": "2023-11-01",
"sort": [
{
"column": "period",
"direction": "desc"
}
],
"offset": 0,
"length": 5000
}

res = s.get(api_url, params={"api_key": eia_key,}, headers={"X-Params": json.dumps(params)})
eia_df = pd.json_normalize(res.json()['response']['data'])
eia_df['datetime'] = pd.to_datetime(eia_df['period'])
eia_df['value'] = eia_df['value'].astype('float')
eia_df['ID'] = eia_df['respondent'] + "_" + eia_df['type'] + "_" + eia_df['timezone']
temp = eia_df.pivot(columns='ID', index='datetime', values='value')
dataset_lists.append(temp)
time.sleep(sleep_seconds)
except Exception as e:
print(f"eia download failed with error {repr(e)}")
try:
api_url_mix = "https://api.eia.gov/v2/electricity/rto/daily-fuel-type-data/data/"
params = {
"frequency": "daily",
"data": [
"value"
],
"facets": {
"respondent": [
respond
],
"timezone": [
"Eastern"
],
"fueltype": [
"COL",
"NG",
"NUC",
"SUN",
"WAT",
"WND",
],
},
"start": None,
"end": None,
"sort": [
{
"column": "period",
"direction": "desc"
}
],
"offset": 0,
"length": 5000,
}
res = s.get(api_url_mix, params={"api_key": eia_key,}, headers={"X-Params": json.dumps(params)})
eia_df = pd.json_normalize(res.json()['response']['data'])
eia_df['datetime'] = pd.to_datetime(eia_df['period'])
eia_df['value'] = eia_df['value'].astype('float')
eia_df['type-name'] = eia_df['type-name'].str.replace(" ", "_")
eia_df['ID'] = eia_df['respondent'] + "_" + eia_df['type-name'] + "_" + eia_df['timezone']
temp = eia_df.pivot(columns='ID', index='datetime', values='value')
dataset_lists.append(temp)
time.sleep(1)
except Exception as e:
print(f"eia download failed with error {repr(e)}")

### End of data download
if len(dataset_lists) < 1:
raise ValueError("No data successfully downloaded!")
Expand Down

0 comments on commit 99c25cd

Please sign in to comment.