diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41c1b91..9303140 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: 🍴 NX-API TEST +name: 🍴 I TEST on: push: diff --git a/README.md b/README.md index 1ffa2aa..74aa716 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## Python NX AI +## I > FastAPI/Python/Postgres/tsvector. Open Source, production ready Python FastAPI/Postgres app for [NX](https://goldlabel.pro?s=python-nx-ai) diff --git a/app/__init__.py b/app/__init__.py index 21735b6..de3a844 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,4 +1,4 @@ """NX AI - FastAPI/Python/Postgres/tsvector""" # Current Version -__version__ = "1.1.0" +__version__ = "1.1.1" diff --git a/app/api/products/update.py b/app/api/products/update.py new file mode 100644 index 0000000..c14a456 --- /dev/null +++ b/app/api/products/update.py @@ -0,0 +1,59 @@ +from fastapi import APIRouter, status +import os, csv, time +from app.api.db import get_db_connection +from app import __version__ + +router = APIRouter() + +@router.get("/products/update", status_code=status.HTTP_202_ACCEPTED) +def update_products() -> dict: + """Process the large big_data.csv file to update products.""" + csv_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'data/big_data.csv')) + process_csv(csv_path) + base_url = os.getenv("BASE_URL", "http://localhost:8000") + epoch = int(time.time() * 1000) + meta = { + "severity": "info", + "title": "Product update from big_data.csv started", + "version": __version__, + "base_url": base_url, + "time": epoch, + } + return {"meta": meta, "data": {"filename": "big_data.csv"}} + +def process_csv(csv_path: str): + conn_gen = get_db_connection() + conn = next(conn_gen) + cur = conn.cursor() + with open(csv_path, newline='') as csvfile: + reader = csv.DictReader(csvfile) + for row in reader: + cur.execute( + """ + UPDATE product SET + Params=%(Params)s, + title=%(desc)s, + UOS=%(UOS)s, + Pack_Description=%(Pack_Description)s, + Hierarchy1=%(Hierarchy1)s, + Hierarchy2=%(Hierarchy2)s, + Hierarchy3=%(Hierarchy3)s, + UOP=%(UOP)s, + sSell1=%(sSell1)s, + sSell2=%(sSell2)s, + sSell3=%(sSell3)s, + sSell4=%(sSell4)s, + sSell5=%(sSell5)s, + pack1=%(pack1)s, + pack2=%(pack2)s, + pack3=%(pack3)s, + pack4=%(pack4)s, + pack5=%(pack5)s, + EAN=%(EAN)s + WHERE item=%(item)s OR EAN=%(EAN)s + """, + row + ) + conn.commit() + cur.close() + conn.close() diff --git a/app/api/root.py b/app/api/root.py index 20a45aa..259f96d 100644 --- a/app/api/root.py +++ b/app/api/root.py @@ -13,8 +13,8 @@ def root() -> dict: base_url = os.getenv("BASE_URL", "http://localhost:8000") epoch = int(time.time() * 1000) meta = { + "title": "How can I help?", "severity": "success", - "title": "How can NX-AI help?", "version": __version__, "base_url": base_url, "time": epoch, @@ -26,7 +26,8 @@ def root() -> dict: "name": "products", "url": f"{base_url}/products", "children": [ - {"name": "seed", "url": f"{base_url}/products/seed"} + {"name": "seed", "url": f"{base_url}/products/seed"}, + {"name": "update", "url": f"{base_url}/products/update"} ] } ] diff --git a/app/api/routes.py b/app/api/routes.py index ec04a6f..61067ba 100644 --- a/app/api/routes.py +++ b/app/api/routes.py @@ -14,8 +14,10 @@ from app.api.health import router as health_router from app.api.products.products import router as products_router from app.api.products.seed import router as seed_router +from app.api.products.update import router as update_router router.include_router(root_router) router.include_router(health_router) router.include_router(products_router) router.include_router(seed_router) +router.include_router(update_router) diff --git a/app/main.py b/app/main.py index cb8a86a..131f17b 100644 --- a/app/main.py +++ b/app/main.py @@ -4,13 +4,11 @@ from fastapi.staticfiles import StaticFiles from fastapi.responses import FileResponse import os - -from app import __version__ from app.api.routes import router app = FastAPI( - title="NX-AI", - description="Production-ready Python FastAPI app for NX", + title="I", + description="Production-ready Python with FastAPI and tsvector", version=__version__, ) diff --git a/render.yaml b/render.yaml index 9769557..4a2a342 100644 --- a/render.yaml +++ b/render.yaml @@ -1,7 +1,7 @@ # Exported from Render on 2026-03-18T18:57:52Z version: "1" projects: -- name: NX AI Python +- name: I environments: - name: Production services: diff --git a/tests/test_routes.py b/tests/test_routes.py index b9f1672..0bf8cf9 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -1,4 +1,4 @@ -"""Unit and integration tests for NX AI routes.""" +"""Unit and integration tests for I endpoints.""" from unittest.mock import MagicMock from fastapi.testclient import TestClient @@ -8,7 +8,7 @@ client = TestClient(app) def test_root_returns_welcome_message() -> None: - """GET / should return a welcome message.""" + """GET / should reply in the first person.""" response = client.get("/") assert response.status_code == 200 json_data = response.json()