mirror of
https://github.com/Benexl/FastAnime.git
synced 2026-01-14 05:46:29 -08:00
renamed app to anixstream
This commit is contained in:
34
anixstream/Utility/yaml_parser.py
Normal file
34
anixstream/Utility/yaml_parser.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import yaml
|
||||
|
||||
import os
|
||||
|
||||
|
||||
class YamlParser:
|
||||
"""makes managing yaml files easier"""
|
||||
|
||||
data = {}
|
||||
|
||||
def __init__(self, file_path: str, default, data_type):
|
||||
self.file_path: str = file_path
|
||||
self.data: data_type
|
||||
if os.path.exists(file_path):
|
||||
try:
|
||||
with open(self.file_path, "r") as yaml_file:
|
||||
self.data = yaml.safe_load(yaml_file)
|
||||
except:
|
||||
self.data = default
|
||||
with open(file_path, "w") as yaml_file:
|
||||
yaml.dump(default, yaml_file)
|
||||
else:
|
||||
self.data = default
|
||||
with open(file_path, "w") as yaml_file:
|
||||
yaml.dump(default, yaml_file)
|
||||
|
||||
def read(self):
|
||||
with open(self.file_path, "r") as yaml_file:
|
||||
self.data = yaml.safe_load(yaml_file)
|
||||
return self.data
|
||||
|
||||
def write(self, new_obj):
|
||||
with open(self.file_path, "w") as yaml_file:
|
||||
yaml.dump(new_obj, yaml_file)
|
||||
Reference in New Issue
Block a user