update main.py
This commit is contained in:
parent
897cd5d7c3
commit
52770c1bce
13
main.py
13
main.py
|
|
@ -17,6 +17,7 @@ from services.geometry_detector import attach_polygon_geometry_auto
|
||||||
from database.connection import engine
|
from database.connection import engine
|
||||||
from database.models import Base
|
from database.models import Base
|
||||||
import time
|
import time
|
||||||
|
from datetime import datetime, timedelta
|
||||||
import pathlib
|
import pathlib
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
|
|
@ -28,7 +29,7 @@ from sqlalchemy import text
|
||||||
|
|
||||||
UPLOAD_FOLDER.mkdir(parents=True, exist_ok=True)
|
UPLOAD_FOLDER.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
apiVersion = "2.1.0"
|
apiVersion = "2.1.3"
|
||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
title="ETL Geo Upload Service",
|
title="ETL Geo Upload Service",
|
||||||
version=apiVersion,
|
version=apiVersion,
|
||||||
|
|
@ -203,17 +204,19 @@ def process_data(df: pd.DataFrame, ext: str):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@app.get("/status", tags=["System"])
|
@app.get("/status", tags=["System"])
|
||||||
async def server_status():
|
async def server_status():
|
||||||
|
utc_time = datetime.utcnow()
|
||||||
|
wib_time = utc_time + timedelta(hours=7)
|
||||||
|
formatted_time = wib_time.strftime("%d-%m-%Y %H:%M:%S")
|
||||||
response = {
|
response = {
|
||||||
"status": "success",
|
"status": "success",
|
||||||
"message": "Server is running smoothly ✅",
|
"message": "Server is running smoothly ✅",
|
||||||
"data": {
|
"data": {
|
||||||
"service": "upload_automation",
|
"service": "upload_automation",
|
||||||
"status_code": 200,
|
"status_code": 200,
|
||||||
"timestamp": datetime.utcnow().isoformat() + "Z",
|
"timestamp": f"{formatted_time} WIB"
|
||||||
},
|
},
|
||||||
"meta": {
|
"meta": {
|
||||||
"version": apiVersion,
|
"version": apiVersion,
|
||||||
|
|
@ -225,7 +228,7 @@ async def server_status():
|
||||||
|
|
||||||
|
|
||||||
@app.post("/upload")
|
@app.post("/upload")
|
||||||
async def upload_file(file: UploadFile = File(...), page: Optional[str] = Form("")):
|
async def upload_file(file: UploadFile = File(...), page: Optional[str] = Form(""), sheet: Optional[str] = Form("")):
|
||||||
fname = file.filename
|
fname = file.filename
|
||||||
ext = os.path.splitext(fname)[1].lower()
|
ext = os.path.splitext(fname)[1].lower()
|
||||||
contents = await file.read()
|
contents = await file.read()
|
||||||
|
|
@ -242,7 +245,7 @@ async def upload_file(file: UploadFile = File(...), page: Optional[str] = Form("
|
||||||
print('ext', ext)
|
print('ext', ext)
|
||||||
|
|
||||||
if ext == ".csv":
|
if ext == ".csv":
|
||||||
df = read_csv(str(tmp_path))
|
df = read_csv(str(tmp_path), sheet)
|
||||||
elif ext == ".xlsx":
|
elif ext == ".xlsx":
|
||||||
df = read_csv(str(tmp_path))
|
df = read_csv(str(tmp_path))
|
||||||
elif ext == ".pdf":
|
elif ext == ".pdf":
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user