-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
29 lines (24 loc) · 828 Bytes
/
main.py
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
# uvicorn main:app --reload
# http://127.0.0.1:8000/?tableName=NOTIFICATIONS
from fastapi import FastAPI
import os
import pandas as pd
import json
app = FastAPI()
@app.get("/")
def read_root(tableName: str):
data_dir = 'extracktedData'
data = []
file_path = os.path.join(data_dir, tableName + '.csv')
if not os.path.exists(file_path):
return {"error": "Belirtilen tablo bulunamadı."}
try:
df = pd.read_csv(file_path, on_bad_lines='skip', sep=';')
if len(df) > 1000:
df = df.tail(1000)
result = df.to_json(orient="index")
parsed = json.loads(result)
data.append(parsed)
return {tableName: data}
except pd.errors.ParserError as e:
return {"error": f"Tablo okunurken bir hata oluştu: {str(e)}"}