Skip to content

Commit 064e9c8

Browse files
Merge pull request #23 from goldlabelapps/staging
This pull request introduces a new endpoint for updating products from a CSV file and updates various naming and branding references throughout the codebase from "NX AI" to "I".
2 parents 1400430 + b8ce5e2 commit 064e9c8

9 files changed

Lines changed: 72 additions & 12 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 🍴 NX-API TEST
1+
name: 🍴 I TEST
22

33
on:
44
push:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Python NX AI
1+
## I
22

33
> FastAPI/Python/Postgres/tsvector.
44
Open Source, production ready Python FastAPI/Postgres app for [NX](https://goldlabel.pro?s=python-nx-ai)

app/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""NX AI - FastAPI/Python/Postgres/tsvector"""
22

33
# Current Version
4-
__version__ = "1.1.0"
4+
__version__ = "1.1.1"

app/api/products/update.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from fastapi import APIRouter, status
2+
import os, csv, time
3+
from app.api.db import get_db_connection
4+
from app import __version__
5+
6+
router = APIRouter()
7+
8+
@router.get("/products/update", status_code=status.HTTP_202_ACCEPTED)
9+
def update_products() -> dict:
10+
"""Process the large big_data.csv file to update products."""
11+
csv_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'data/big_data.csv'))
12+
process_csv(csv_path)
13+
base_url = os.getenv("BASE_URL", "http://localhost:8000")
14+
epoch = int(time.time() * 1000)
15+
meta = {
16+
"severity": "info",
17+
"title": "Product update from big_data.csv started",
18+
"version": __version__,
19+
"base_url": base_url,
20+
"time": epoch,
21+
}
22+
return {"meta": meta, "data": {"filename": "big_data.csv"}}
23+
24+
def process_csv(csv_path: str):
25+
conn_gen = get_db_connection()
26+
conn = next(conn_gen)
27+
cur = conn.cursor()
28+
with open(csv_path, newline='') as csvfile:
29+
reader = csv.DictReader(csvfile)
30+
for row in reader:
31+
cur.execute(
32+
"""
33+
UPDATE product SET
34+
Params=%(Params)s,
35+
title=%(desc)s,
36+
UOS=%(UOS)s,
37+
Pack_Description=%(Pack_Description)s,
38+
Hierarchy1=%(Hierarchy1)s,
39+
Hierarchy2=%(Hierarchy2)s,
40+
Hierarchy3=%(Hierarchy3)s,
41+
UOP=%(UOP)s,
42+
sSell1=%(sSell1)s,
43+
sSell2=%(sSell2)s,
44+
sSell3=%(sSell3)s,
45+
sSell4=%(sSell4)s,
46+
sSell5=%(sSell5)s,
47+
pack1=%(pack1)s,
48+
pack2=%(pack2)s,
49+
pack3=%(pack3)s,
50+
pack4=%(pack4)s,
51+
pack5=%(pack5)s,
52+
EAN=%(EAN)s
53+
WHERE item=%(item)s OR EAN=%(EAN)s
54+
""",
55+
row
56+
)
57+
conn.commit()
58+
cur.close()
59+
conn.close()

app/api/root.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def root() -> dict:
1313
base_url = os.getenv("BASE_URL", "http://localhost:8000")
1414
epoch = int(time.time() * 1000)
1515
meta = {
16+
"title": "How can I help?",
1617
"severity": "success",
17-
"title": "How can NX-AI help?",
1818
"version": __version__,
1919
"base_url": base_url,
2020
"time": epoch,
@@ -26,7 +26,8 @@ def root() -> dict:
2626
"name": "products",
2727
"url": f"{base_url}/products",
2828
"children": [
29-
{"name": "seed", "url": f"{base_url}/products/seed"}
29+
{"name": "seed", "url": f"{base_url}/products/seed"},
30+
{"name": "update", "url": f"{base_url}/products/update"}
3031
]
3132
}
3233
]

app/api/routes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
from app.api.health import router as health_router
1515
from app.api.products.products import router as products_router
1616
from app.api.products.seed import router as seed_router
17+
from app.api.products.update import router as update_router
1718

1819
router.include_router(root_router)
1920
router.include_router(health_router)
2021
router.include_router(products_router)
2122
router.include_router(seed_router)
23+
router.include_router(update_router)

app/main.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
from fastapi.staticfiles import StaticFiles
55
from fastapi.responses import FileResponse
66
import os
7-
8-
from app import __version__
97
from app.api.routes import router
108

119
app = FastAPI(
12-
title="NX-AI",
13-
description="Production-ready Python FastAPI app for NX",
10+
title="I",
11+
description="Production-ready Python with FastAPI and tsvector",
1412
version=__version__,
1513
)
1614

render.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Exported from Render on 2026-03-18T18:57:52Z
22
version: "1"
33
projects:
4-
- name: NX AI Python
4+
- name: I
55
environments:
66
- name: Production
77
services:

tests/test_routes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Unit and integration tests for NX AI routes."""
1+
"""Unit and integration tests for I endpoints."""
22

33
from unittest.mock import MagicMock
44
from fastapi.testclient import TestClient
@@ -8,7 +8,7 @@
88
client = TestClient(app)
99

1010
def test_root_returns_welcome_message() -> None:
11-
"""GET / should return a welcome message."""
11+
"""GET / should reply in the first person."""
1212
response = client.get("/")
1313
assert response.status_code == 200
1414
json_data = response.json()

0 commit comments

Comments
 (0)