File size: 1,063 Bytes
36a276a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import json


class FileSystemReader:

    BASE_DIR = os.path.dirname(os.path.dirname(__file__))
    DATA_DIR = os.path.join(BASE_DIR, "data")

    def __init__(self, file_name):

        self.file_name = file_name
        self.file_path = self.build_path()

    def build_path(self):

        # ✅ FIX: if absolute path is given, use it directly
        if os.path.isabs(self.file_name):
            return self.file_name

        return os.path.join(self.DATA_DIR, self.file_name)

    def read_file(self):

        try:
            with open(self.file_path, "r", encoding="utf-8") as file:
                return json.load(file)

        except FileNotFoundError:
            return {
                "success": False,
                "message": f"File not found: {self.file_path}",
                "data": None
            }

        except json.JSONDecodeError as e:
            return {
                "success": False,
                "message": "Invalid JSON format",
                "error": str(e),
                "data": None
            }