-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapollo.py
More file actions
29 lines (27 loc) · 1.16 KB
/
Copy pathapollo.py
File metadata and controls
29 lines (27 loc) · 1.16 KB
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
import os
import csv
import time
from fastapi import APIRouter, HTTPException
from app.utils.make_meta import make_meta
from app.utils.db import get_db_connection_direct
router = APIRouter()
@router.post("/queue/csv/apollo")
def import_apollo_csv() -> dict:
"""POST /queue/csv/apollo: Import data from apollo.csv into the queue table (template)."""
csv_path = os.path.join(os.path.dirname(__file__), "../csv/apollo/seed.csv")
if not os.path.exists(csv_path):
raise HTTPException(status_code=404, detail="seed.csv not found")
try:
conn = get_db_connection_direct()
cursor = conn.cursor()
# TODO: Implement CSV parsing and DB insertion logic for Apollo format
# Example placeholder for batch import logic:
# with open(csv_path, newline='', encoding='utf-8') as csvfile:
# reader = csv.DictReader(csvfile)
# for row in reader:
# pass # Process each row
conn.commit()
conn.close()
return {"meta": make_meta("success", "Apollo CSV import template executed"), "imported": 0}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))