This commit is contained in:
Nicole Rappe 2025-02-25 21:00:51 -07:00
parent d66dcfefd5
commit 1cab85ac87
2 changed files with 8 additions and 49 deletions

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
""" """
Flyff EXP Node (Final Combined Version) Flyff EXP Node (Final Combined Version)
- Polls the API at http://127.0.0.1:5000/data - Pulls the EXP value directly from data_manager.py
- Outputs only the "exp" value as a string - Outputs only the "exp" value as a string
- Uses color (48, 116, 143) for its output port - Uses color (48, 116, 143) for its output port
- Displays "exp" in a text field labeled "Value" - Displays "exp" in a text field labeled "Value"
@ -9,9 +9,9 @@ Flyff EXP Node (Final Combined Version)
""" """
import time import time
import requests
import traceback import traceback
from OdenGraphQt import BaseNode from OdenGraphQt import BaseNode
from Modules import data_manager # Importing data_manager from Modules
class FlyffEXPCurrentNode(BaseNode): class FlyffEXPCurrentNode(BaseNode):
__identifier__ = 'bunny-lab.io.flyff_exp_current_node' __identifier__ = 'bunny-lab.io.flyff_exp_current_node'
@ -26,50 +26,17 @@ class FlyffEXPCurrentNode(BaseNode):
# 2) Output port also named "value" # 2) Output port also named "value"
self.add_output('value', color=(48, 116, 143)) self.add_output('value', color=(48, 116, 143))
self._api_down = True self.set_name("Flyff - EXP")
self._last_api_attempt = 0.0
self._retry_interval = 5.0
self._last_error_printed = 0.0
self.set_name("Flyff - EXP (API Disconnected)")
def process_input(self): def process_input(self):
current_time = time.time()
if self._api_down and (current_time - self._last_api_attempt < self._retry_interval):
return
self._last_api_attempt = current_time
try: try:
response = requests.get("http://127.0.0.1:5000/data", timeout=1) new_value = data_manager.get_data().get("exp", "N/A")
status_code = response.status_code
if status_code == 200:
try:
data = response.json() or {}
except ValueError:
data = {}
if isinstance(data, list):
data = {}
self._api_down = False
self.set_name("Flyff - EXP (API Connected)")
new_value = data.get("exp", "N/A")
new_value_str = str(new_value) new_value_str = str(new_value)
self.set_property('value', new_value_str) self.set_property('value', new_value_str)
self.transmit_data(new_value_str) self.transmit_data(new_value_str)
else:
self._handle_api_error(f"HTTP {status_code} from FlyffEXPCurrentNode")
self._api_down = True
except Exception as e: except Exception as e:
tb = traceback.format_exc() tb = traceback.format_exc()
self._handle_api_error(f"Exception in FlyffEXPCurrentNode: {e}\nTraceback:\n{tb}") print(f"[ERROR] Exception in FlyffEXPCurrentNode: {e}\nTraceback:\n{tb}")
self._api_down = True
def transmit_data(self, data): def transmit_data(self, data):
output_port = self.outputs().get('value') output_port = self.outputs().get('value')
@ -81,11 +48,3 @@ class FlyffEXPCurrentNode(BaseNode):
connected_node.receive_data(data, source_port_name='value') connected_node.receive_data(data, source_port_name='value')
except Exception as e: except Exception as e:
print(f"[ERROR] Error transmitting data to {connected_node}: {e}") print(f"[ERROR] Error transmitting data to {connected_node}: {e}")
def _handle_api_error(self, msg):
current_time = time.time()
if (current_time - self._last_error_printed) >= self._retry_interval:
print(f"[ERROR] {msg}")
self._last_error_printed = current_time
self.set_name("Flyff - EXP (API Disconnected)")