Updated pathing
This commit is contained in:
@@ -1,20 +1,38 @@
|
|||||||
import os
|
from pathlib import Path
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
working_directory = Path(__file__).parent
|
||||||
|
|
||||||
load_dotenv()
|
try:
|
||||||
|
with open(str(working_directory / "settings.json"), "rt") as settings_file:
|
||||||
|
settings = json.load(settings_file)
|
||||||
|
checklist_file_path = settings.get("checklist_storage_path", str(working_directory / "json")) + "/checklists.json"
|
||||||
|
ingredients_file_path = settings.get("meal_storage_path", str(working_directory / "json")) + "/ingredients.json"
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
with open(str(working_directory / "settings.json"), "w") as settings_file:
|
||||||
|
settings = {
|
||||||
|
"meal_storage_path": str(working_directory / "json"),
|
||||||
|
"checklist_storage_path": str(working_directory / "json")
|
||||||
|
}
|
||||||
|
json.dump(settings, settings_file, indent=4)
|
||||||
|
checklist_file_path = settings["checklist_storage_path"] + "/checklists.json"
|
||||||
|
ingredients_file_path = settings["meal_storage_path"] + "/ingredients.json"
|
||||||
|
|
||||||
checklist_file_path = os.getenv("FILE_PATH") + "/checklist.md" if os.getenv("FILE_PATH") else "./checklist.md"
|
def read_ingredient_json() -> dict:
|
||||||
|
|
||||||
ingredients_file_path = "./src/json/ingredients.json"
|
|
||||||
|
|
||||||
def read_json() -> dict:
|
|
||||||
try:
|
try:
|
||||||
with open(ingredients_file_path, "rt") as file:
|
with open(ingredients_file_path, "rt") as file:
|
||||||
return json.load(file)
|
return json.load(file)
|
||||||
except:
|
except:
|
||||||
print("Could not find or read file.")
|
print("Could not find or read ingredients file.")
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def read_json_file(filename: str) -> dict:
|
||||||
|
try:
|
||||||
|
with open(filename, "rt") as file:
|
||||||
|
return json.load(file)
|
||||||
|
except:
|
||||||
|
print(f"Could not find or read file.\n{filename=}")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def update_json(meals: dict) -> None:
|
def update_json(meals: dict) -> None:
|
||||||
@@ -24,8 +42,15 @@ def update_json(meals: dict) -> None:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Unable to write data to file. {e}")
|
print(f"Unable to write data to file. {e}")
|
||||||
|
|
||||||
|
def update_file(filename: str, content: dict) -> None:
|
||||||
|
try:
|
||||||
|
with open(filename, "w") as file:
|
||||||
|
json.dump(content, file, indent=4)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Unable to write data to file. {e}")
|
||||||
|
|
||||||
def get_selected_meals(meals: dict) -> dict:
|
def get_selected_meals(meals: dict) -> dict:
|
||||||
meal_json = read_json()
|
meal_json = read_ingredient_json()
|
||||||
selected_meals = {}
|
selected_meals = {}
|
||||||
if meal_json:
|
if meal_json:
|
||||||
for meal in meals:
|
for meal in meals:
|
||||||
@@ -57,7 +82,7 @@ def write_checklist(data: dict) -> None:
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
meals = read_json()
|
meals = read_ingredient_json()
|
||||||
if meals:
|
if meals:
|
||||||
combined_ingredients = combine_ingredients(meals)
|
combined_ingredients = combine_ingredients(meals)
|
||||||
write_checklist(combined_ingredients)
|
write_checklist(combined_ingredients)
|
||||||
Reference in New Issue
Block a user