def forecast(): # Input start = datetime.now() - timedelta(hours=5) end = datetime.now() + timedelta(hours=24) country_code = 'FR' # France # Print attempt time print('Job executed at ' + str(datetime.now())) print('Fetching forecast from ' + str(start) + ' to ' + str(end)) # Query data client = EntsoePandasClient(api_key=setting.key) ts = client.query_load_forecast(country_code, start=start, end=end) # We could concat historical data to have an accurate curve afterward #client.query_load(country_code, start=start - timedelta(hours=24),end=end) # Print sucess time range print('Retrieved forecast from ' + str(ts.index[0]) + ' to ' + str(ts.index[-1])) # Resample data (make sure time ends in 0 or 5) forecast = ts.resample('5T').interpolate() # Send data over to server url = 'http://fastapi/forecast' data = { 'times': [d.strftime('%Y-%m-%dT%H:%M:%SZ') for d in forecast.index], 'values': list((forecast / 1000 - 42.5).tolist()) } headers = {"Content-Type": "application/json"} response = requests.put(url, data=json.dumps(data), headers=headers) res = response.json() print('Forecast request result ' + str(res))
# ============================================================================= #""" key = str(np.genfromtxt('entsoe.txt', dtype='str')) client = EntsoePandasClient(api_key=key) # Time Series # NoMatchingDataError # ts_day_ahead = client.query_day_ahead_prices(country_code, start=start,end=end) ts_load = client.query_load(country_code, start=start, end=end) ts_load.to_csv('data_base/ts_load.csv') ts_load_forecast = client.query_load_forecast(country_code, start=start, end=end) ts_load_forecast.to_csv('data_base/ts_load_forecast.csv') ts_generation_forecast = client.query_generation_forecast(country_code, start=start, end=end) ts_generation_forecast.to_csv('data_base/ts_generation_forecast.csv') # Dataframes df_wind_and_solar_forecast = client.query_wind_and_solar_forecast( country_code, start=start, end=end, psr_type=None) df_wind_and_solar_forecast.to_csv('data_base/df_wind_and_solar_forecast.csv') df_generation = client.query_generation(country_code,
from entsoe import EntsoePandasClient import sqlite3 import pandas as pd from datetime import date, timedelta import time end_date = date.today() + timedelta(days=1) current_date = end_date.strftime("%Y%m%d") client = EntsoePandasClient(api_key='444fc771-5d0f-499f-9328-90c05c459219') start = pd.Timestamp('20201109', tz='Europe/Brussels') end = pd.Timestamp(current_date, tz='Europe/Brussels') country_code = 'DE' generation = client.query_load(country_code, start=start, end=end) generation1.to_csv('outfile1.csv') print(generation1) start = pd.Timestamp('20201109', tz='Europe/Brussels') end_date = date.today() + timedelta(days=2) current_date = end_date.strftime("%Y%m%d") end = pd.Timestamp(current_date, tz='Europe/Brussels') country_code = 'DE' generation2 = client.query_load_forecast(country_code, start=start, end=end) generation2.to_csv('outfile2.csv') print(generation2)