import requests
from klipper import connect
class dynamicvariables:
def __init__(self, config):
self.printer = config.get_printer()
self.reactor = self.printer.get_reactor()
self.gcode = self.printer.lookup_object('gcode')
self.printer.register_event_handler("print_start", self.on_print_start)
self.metadata = {}
@classmethod
def get_moonraker_metadata(cls, filename, moonraker_url="http://localhost:7125"):
url = f"{moonraker_url}/server/files/metadata?filename={filename}"
try:
response = requests.get(url)
response.raise_for_status() # Raise an exception for error HTTP statuses
data = response.json()
return data['result']
except requests.exceptions.RequestException as e:
print(f"Error fetching metadata: {e}")
return None
def on_print_start(self, event_time):
filename = event_time['file']
self.metadata = self.get_moonraker_metadata(filename)
def load_config(config):
return dynamicvariables(config)
I have this file saved as “dynamicvariables.py” in the /klipper/klippy/extras folder.
When trying to load it via cfg file, I just receive the following error:
Section 'dynamicvariables' is not a valid config section
What am I doing wrong?