Update app.py
Browse files
app.py
CHANGED
|
@@ -52,27 +52,25 @@ def get_csv_file(csv_docs):
|
|
| 52 |
|
| 53 |
|
| 54 |
# json ๋ฌธ์๋ก๋ถํฐ ํ
์คํธ๋ฅผ ์ถ์ถํ๋ ํจ์
|
| 55 |
-
|
| 56 |
-
def
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
return f"Invalid JSON format: {e}"
|
| 75 |
-
|
| 76 |
|
| 77 |
|
| 78 |
|
|
|
|
| 52 |
|
| 53 |
|
| 54 |
# json ๋ฌธ์๋ก๋ถํฐ ํ
์คํธ๋ฅผ ์ถ์ถํ๋ ํจ์
|
| 55 |
+
class JSONLoader:
|
| 56 |
+
def __init__(self, file_path, jq_schema):
|
| 57 |
+
self.file_path = file_path
|
| 58 |
+
self.jq_schema = jq_schema
|
| 59 |
+
|
| 60 |
+
def load(self):
|
| 61 |
+
with open(self.file_path, 'r') as json_file:
|
| 62 |
+
data = json.load(json_file)
|
| 63 |
+
users_text = [user.get('text', '') for user in data.get('users', [])]
|
| 64 |
+
return users_text
|
| 65 |
+
|
| 66 |
+
def get_json_file(json_docs):
|
| 67 |
+
temp_dir = tempfile.TemporaryDirectory()
|
| 68 |
+
temp_filepath = os.path.join(temp_dir.name, json_docs.name)
|
| 69 |
+
with open(temp_filepath, "wb") as f:
|
| 70 |
+
f.write(json_docs.getvalue())
|
| 71 |
+
json_loader = JSONLoader(temp_filepath, jq_schema={})
|
| 72 |
+
users_text = json_loader.load()
|
| 73 |
+
return users_text
|
|
|
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
|