initial commit

This commit is contained in:
ChrisColeTech
2024-08-14 01:00:38 -04:00
parent 003ddc3fb4
commit 9cb7801c10
2 changed files with 62 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
from line_counter import TextFileLineCounter
NODE_CLASS_MAPPINGS = {
"TextFileLineCounter": TextFileLineCounter,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"TextFileLineCounter": "🤑 Text File Line Counter",
}
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']
+50
View File
@@ -0,0 +1,50 @@
import os
class TextFileLineCounter():
def __init__(self):
pass
RETURN_TYPES = ("INT","NUMBER","STRING") # Ensure this matches ComfyUI's expectations
RETURN_NAMES = ()
FUNCTION = "count_lines"
CATEGORY = "line_counter"
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"file_path": ("STRING", {"default": "", "multiline": False}),
},
}
@classmethod
def OUTPUT_TYPES(cls):
return {
"outputs": {
"line_count_int": ("INT",),
"line_count_number": ("NUMBER",),
"line_count_string": ("STRING",),
},
}
def count_lines(self, file_path: str) -> dict:
if not os.path.isfile(file_path):
raise FileNotFoundError(f"The file at path '{file_path}' does not exist.")
with open(file_path, 'r', encoding='utf-8') as file:
lines = file.readlines()
line_count = len([line for line in lines if line.strip() != ""]) - 1
return {
"line_count_int": line_count, # Integer
"line_count_number": float(line_count), # Number (float)
"line_count_string": str(line_count) # String
}
def test(self):
return ()
NODE_CLASS_MAPPINGS = {
"TextFileLineCounter": TextFileLineCounter,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"TextFileLineCounter": "🤑 Text File Line Counter",
}