-
Notifications
You must be signed in to change notification settings - Fork 0
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
9 changed files
with
103 additions
and
45 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,7 @@ | ||
class FileData: | ||
def __init__(self, last_modified=0, contents=None): | ||
self.last_modified = last_modified | ||
self.contents = contents | ||
|
||
def __getitem__(self, key, default=None): | ||
return self.contents.get(key, default) |
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
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,62 @@ | ||
|
||
import os | ||
from file_data import FileData | ||
import yaml | ||
from types import SimpleNamespace | ||
from yamlpath.common import Parsers | ||
from yamlpath.wrappers import ConsolePrinter | ||
from yamlpath import Processor | ||
from yamlpath import YAMLPath | ||
from yamlpath.exceptions import YAMLPathException | ||
|
||
class YamlParser: | ||
def __init__(self): | ||
self.file_cache = {} | ||
self.pwd = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
logging_args = SimpleNamespace(quiet=True, verbose=False, debug=False) | ||
log = ConsolePrinter(logging_args) | ||
parser = Parsers.get_yaml_editor() | ||
|
||
# At this point, you'd load or parse your YAML file, stream, or string. This | ||
# example demonstrates loading YAML data from an external file. You could also | ||
# use the same function to load data from STDIN or even a String variable. See | ||
# the Parser class for more detail. | ||
self.layout = os.path.join(self.pwd, "configs/layout.yml") | ||
print(self.layout) | ||
(yaml_data, doc_loaded) = Parsers.get_yaml_data(parser, log, self.layout) | ||
if not doc_loaded: | ||
# There was an issue loading the file; an error message has already been | ||
# printed via ConsolePrinter. | ||
exit(1) | ||
|
||
# Pass the logging facility and parsed YAML data to the YAMLPath Processor | ||
self.processor = Processor(log, yaml_data) | ||
|
||
def find_widget(self, widget_name): | ||
yaml_path = YAMLPath(f"/tabs/*/widgets[name = '{widget_name}']") | ||
|
||
try: | ||
for node in self.processor.get_nodes(yaml_path, return_coordinates=True, return_node=True, mustexist=True): | ||
return node.node | ||
except YAMLPathException as ex: | ||
print(ex) | ||
|
||
return None | ||
|
||
|
||
def load_layout(self): | ||
file_path = self.layout | ||
|
||
# Check the last modification time of the file | ||
current_modified_time = os.path.getmtime(file_path) | ||
|
||
# Only load the file if it has been modified since the last check or if there is no value for that file in the dict | ||
if current_modified_time > self.file_cache.get(file_path, FileData()).last_modified or file_path not in self.file_cache: | ||
with open(file_path, 'r') as file: | ||
contents = yaml.safe_load(file) | ||
self.file_cache[file_path] = FileData(current_modified_time, contents) | ||
|
||
return self.file_cache[file_path].contents | ||
|
||
yaml_parser = YamlParser() |
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
aiohttp[speedups] | ||
argcomplete | ||
bs4 | ||
docker | ||
feedparser | ||
Flask-Minify | ||
flask[async] | ||
flask-caching | ||
Flask-Minify | ||
hypercorn==0.15.0 | ||
langchain | ||
langchain-community | ||
lxml | ||
python-dotenv | ||
pyyaml | ||
pyyaml | ||
requests | ||
hypercorn==0.15.0 | ||
aiohttp[speedups] | ||
yamlpath |