Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 🍴 NX-API TEST
name: 🍴 I TEST

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""NX AI - FastAPI/Python/Postgres/tsvector"""

# Current Version
__version__ = "1.1.0"
__version__ = "1.1.1"
59 changes: 59 additions & 0 deletions app/api/products/update.py
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 3 additions & 2 deletions app/api/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"}
]
}
]
Expand Down
2 changes: 2 additions & 0 deletions app/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 2 additions & 4 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__,
)

Expand Down
2 changes: 1 addition & 1 deletion render.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down
Loading