-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
366 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class Everything(str): | ||
def __ne__(self, __value: object) -> bool: | ||
return False | ||
|
||
class AnythingToFloat: | ||
@classmethod | ||
def INPUT_TYPES(s): | ||
return { | ||
"required": { | ||
"anything": (Everything("*"), {"forceInput": True}), | ||
}, | ||
} | ||
|
||
@classmethod | ||
def VALIDATE_INPUTS(s, input_types): | ||
return True | ||
|
||
RETURN_TYPES = ("FLOAT",) | ||
RETURN_NAMES = ("float",) | ||
FUNCTION = "any_to_float" | ||
CATEGORY = "Bjornulf" | ||
|
||
def any_to_float(self, anything): | ||
try: | ||
return (float(anything),) | ||
except (ValueError, TypeError): | ||
# Return 0.0 if conversion fails | ||
return (0.0,) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class Everything(str): | ||
def __ne__(self, __value: object) -> bool: | ||
return False | ||
|
||
class AnythingToInt: | ||
@classmethod | ||
def INPUT_TYPES(s): | ||
return { | ||
"required": { | ||
"anything": (Everything("*"), {"forceInput": True}), | ||
}, | ||
} | ||
|
||
@classmethod | ||
def VALIDATE_INPUTS(s, input_types): | ||
return True | ||
|
||
RETURN_TYPES = ("INT",) | ||
RETURN_NAMES = ("integer",) | ||
FUNCTION = "any_to_int" | ||
CATEGORY = "Bjornulf" | ||
|
||
def any_to_int(self, anything): | ||
try: | ||
# Handle string inputs that might be floats | ||
if isinstance(anything, str) and '.' in anything: | ||
return (int(float(anything)),) | ||
# Handle other types | ||
return (int(anything),) | ||
except (ValueError, TypeError): | ||
# Return 0 if conversion fails | ||
return (0,) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import os | ||
|
||
class LoadTextFromFolder: | ||
@classmethod | ||
def INPUT_TYPES(cls): | ||
"""Define input parameters for the node""" | ||
default_dir = "Bjornulf/Text" | ||
available_files = [] | ||
|
||
if os.path.exists(default_dir): | ||
available_files = [f for f in os.listdir(default_dir) | ||
if f.lower().endswith('.txt')] | ||
|
||
if not available_files: | ||
available_files = ["no_files_found"] | ||
|
||
return { | ||
"required": { | ||
"text_file": (available_files, {"default": available_files[0]}), | ||
} | ||
} | ||
|
||
RETURN_TYPES = ("STRING", "STRING", "STRING") | ||
RETURN_NAMES = ("text", "filename", "full_path") | ||
FUNCTION = "load_text" | ||
CATEGORY = "Bjornulf" | ||
|
||
def load_text(self, text_file): | ||
try: | ||
if text_file == "no_files_found": | ||
raise ValueError("No text files found in Bjornulf/Text folder") | ||
|
||
filepath = os.path.join("Bjornulf/Text", text_file) | ||
|
||
# Check if file exists | ||
if not os.path.exists(filepath): | ||
raise ValueError(f"File not found: {filepath}") | ||
|
||
# Get absolute path | ||
full_path = os.path.abspath(filepath) | ||
|
||
# Get just the filename | ||
filename = os.path.basename(filepath) | ||
|
||
# Read text from file | ||
with open(filepath, 'r', encoding='utf-8') as file: | ||
text = file.read() | ||
|
||
return (text, filename, full_path) | ||
|
||
except (OSError, IOError) as e: | ||
raise ValueError(f"Error loading file: {str(e)}") | ||
|
||
class LoadTextFromPath: | ||
@classmethod | ||
def INPUT_TYPES(cls): | ||
"""Define input parameters for the node""" | ||
return { | ||
"required": { | ||
"file_path": ("STRING", {"default": "Bjornulf/Text/example.txt"}), | ||
} | ||
} | ||
|
||
RETURN_TYPES = ("STRING", "STRING", "STRING") | ||
RETURN_NAMES = ("text", "filename", "full_path") | ||
FUNCTION = "load_text" | ||
CATEGORY = "Bjornulf" | ||
|
||
def load_text(self, file_path): | ||
try: | ||
# Validate file extension | ||
if not file_path.lower().endswith('.txt'): | ||
raise ValueError("File must be a .txt file") | ||
|
||
# Check if file exists | ||
if not os.path.exists(file_path): | ||
raise ValueError(f"File not found: {file_path}") | ||
|
||
# Get absolute path | ||
full_path = os.path.abspath(file_path) | ||
|
||
# Get just the filename | ||
filename = os.path.basename(file_path) | ||
|
||
# Read text from file | ||
with open(file_path, 'r', encoding='utf-8') as file: | ||
text = file.read() | ||
|
||
return (text, filename, full_path) | ||
|
||
except (OSError, IOError) as e: | ||
raise ValueError(f"Error loading file: {str(e)}") |
Oops, something went wrong.