Skip to content

Commit

Permalink
chore: replacing print with logging
Browse files Browse the repository at this point in the history
  • Loading branch information
alirashidAR committed Jan 8, 2025
1 parent 48ff6c9 commit a3ef323
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/open_data_pvnet/scripts/fetch_pvlive_data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from datetime import datetime
from pvlive_api import PVLive
import logging
import pytz


logger = logging.getLogger(__name__)

class PVLiveData:
def __init__(self):
self.pvl = PVLive()
Expand All @@ -14,7 +18,7 @@ def get_latest_data(self, period, entity_type="gsp", entity_id=0, extra_fields="
df = self.pvl.latest(entity_type=entity_type, entity_id=entity_id, extra_fields=extra_fields, period=period, dataframe=True)
return df
except Exception as e:
print(f"Error: {e}")
logger.error(e)
return None

def get_data_between(self, start, end, entity_type="gsp", entity_id=0, extra_fields=""):
Expand All @@ -25,7 +29,7 @@ def get_data_between(self, start, end, entity_type="gsp", entity_id=0, extra_fie
df = self.pvl.between(start=start, end=end, entity_type=entity_type, entity_id=entity_id, extra_fields=extra_fields, dataframe=True)
return df
except Exception as e:
print(f"Error: {e}")
logger.error(e)
return None

def get_data_at_time(self, dt):
Expand All @@ -36,24 +40,7 @@ def get_data_at_time(self, dt):
df = self.pvl.at_time(dt, entity_type="pes", entity_id=0, extra_fields="", period=30, dataframe=True)
return df
except Exception as e:
print(f"Error: {e}")
logger.error(e)
return None


# Example usage
pvl = PVLiveData()

# Get the latest data
latest_data = pvl.get_latest_data(period=30)
print(latest_data)

# Get the data between two dates
start = datetime(2021, 1, 1, 12, 0, tzinfo=pytz.utc)
end = datetime(2021, 1, 2, 12, 0, tzinfo=pytz.utc)
data_between = pvl.get_data_between(start, end)
print(data_between)

# Get the data at a specific time
dt = datetime(2021, 1, 1, 12, 0, tzinfo=pytz.utc)
data_at_time = pvl.get_data_at_time(dt)
print(data_at_time)

0 comments on commit a3ef323

Please sign in to comment.