Update app.py
Browse files
app.py
CHANGED
|
@@ -46,13 +46,25 @@ def get_csv_file(csv_docs):
|
|
| 46 |
csv_loader = CSVLoader(temp_filepath)
|
| 47 |
csv_doc = csv_loader.load()
|
| 48 |
return csv_doc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
def get_json_file(json_docs):
|
| 51 |
temp_dir = tempfile.TemporaryDirectory()
|
| 52 |
temp_filepath = os.path.join(temp_dir.name, json_docs.name)
|
| 53 |
with open(temp_filepath, "wb") as f:
|
| 54 |
f.write(json_docs.getvalue())
|
| 55 |
-
json_loader = JSONLoader(temp_filepath)
|
| 56 |
json_doc = json_loader.load()
|
| 57 |
return json_doc
|
| 58 |
|
|
|
|
| 46 |
csv_loader = CSVLoader(temp_filepath)
|
| 47 |
csv_doc = csv_loader.load()
|
| 48 |
return csv_doc
|
| 49 |
+
|
| 50 |
+
class JSONLoader:
|
| 51 |
+
def __init__(self, file_path, jq_schema):
|
| 52 |
+
self.file_path = file_path
|
| 53 |
+
self.jq_schema = jq_schema
|
| 54 |
+
|
| 55 |
+
def load(self):
|
| 56 |
+
with open(self.file_path, 'r') as json_file:
|
| 57 |
+
data = json.load(json_file)
|
| 58 |
+
# ์ฌ๊ธฐ์ jq_schema๋ฅผ ํ์ฉํ์ฌ ๋ฐ์ดํฐ๋ฅผ ์ฒ๋ฆฌํ๋ ์์
์ ์ํํ ๊ฒ์ผ๋ก ๊ฐ์ ํฉ๋๋ค.
|
| 59 |
+
processed_data = process_with_schema(data, self.jq_schema)
|
| 60 |
+
return processed_data
|
| 61 |
|
| 62 |
def get_json_file(json_docs):
|
| 63 |
temp_dir = tempfile.TemporaryDirectory()
|
| 64 |
temp_filepath = os.path.join(temp_dir.name, json_docs.name)
|
| 65 |
with open(temp_filepath, "wb") as f:
|
| 66 |
f.write(json_docs.getvalue())
|
| 67 |
+
json_loader = JSONLoader(temp_filepath, jq_schema={})
|
| 68 |
json_doc = json_loader.load()
|
| 69 |
return json_doc
|
| 70 |
|