[sheet-service] available get catalogs

This commit is contained in:
Ittipat Lusuk 2026-04-23 14:47:48 +07:00
parent 605e99366a
commit 6201dae51d
2 changed files with 47 additions and 47 deletions

View file

@ -14,8 +14,8 @@ services:
# - ./tsv_data:/app/tsv_data
restart: always
command: uvicorn main:app --host 0.0.0.0 --port 8124
networks:
- kong-net
# networks:
# - kong-net
nginx:
image: nginx:latest
@ -25,10 +25,10 @@ services:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8080:80"
networks:
- kong-net
# networks:
# - kong-net
networks:
kong-net:
external: true
name: kong-api-gateway_kong-ee-net
# networks:
# kong-net:
# external: true
# name: kong-api-gateway_kong-ee-net

78
main.py
View file

@ -851,53 +851,53 @@ def startup_event():
thread = threading.Thread(target=redis_message_handler, daemon=True)
thread.start()
# @app.post("/catalogs")
# def get_catalogs(req: CatalogRequest):
# payload = req.payload
# if payload.srv_name != SERVICE_NAME:
# raise HTTPException(status_code=400, detail="Invalid service name")
@app.post("/catalogs")
def get_api_catalogs(req: CatalogRequest):
payload = req.payload
if payload.srv_name != SERVICE_NAME:
raise HTTPException(status_code=400, detail="Invalid service name")
# country = payload.values.country.strip().lower()
# config = COUNTRY_MAPPING.get(country)
country = payload.values.country.strip().lower()
config = COUNTRY_MAPPING.get(country)
# if not config or not config["sheets"]:
# raise HTTPException(status_code=404, detail="Country or sheets not found")
if not config or not config["sheets"]:
raise HTTPException(status_code=404, detail="Country or sheets not found")
# try:
# # First sheet in Map
# target_sheet_name = config["sheets"][0]
# client = get_gspread_client()
# spreadsheet = client.open_by_key(config["spreadsheet_id"])
# worksheet = spreadsheet.worksheet(target_sheet_name)
try:
# First sheet in Map
target_sheet_name = config["sheets"][0]
client = get_gspread_client()
spreadsheet = client.open_by_key(config["spreadsheet_id"])
worksheet = spreadsheet.worksheet(target_sheet_name)
# # Get A column
# col_a = worksheet.col_values(1)
# Get A column
col_a = worksheet.col_values(1)
# catalogs = []
# # Skip Row 1 (Index 0 in List)
# for row_idx in range(1, len(col_a)):
# val = col_a[row_idx].strip()
# if not val or val in ["-", "IGNORE"]:
# continue
catalogs = []
# Skip Row 1 (Index 0 in List)
for row_idx in range(1, len(col_a)):
val = col_a[row_idx].strip()
if not val or val in ["-", "IGNORE"]:
continue
# # Specify file=...
# # format: Name=Test,file=page_catalog_group_recommend.skt
# match = re.search(r'file=([^,]+)', val)
# if match:
# catalog_name = match.group(1).strip()
# lock_info = lock_manager.get_lock_info(country, catalog_name)
# catalogs.append({
# "catalog": catalog_name,
# "row_index": row_idx + 1, # Index in Google Sheet
# "status": "locked" if lock_info["is_locked"] else "free",
# "locked_by": lock_info["locked_by"]
# })
# Specify file=...
# format: Name=Test,file=page_catalog_group_recommend.skt
match = re.search(r'file=([^,]+)', val)
if match:
catalog_name = match.group(1).strip()
lock_info = lock_manager.get_lock_info(country, catalog_name)
catalogs.append({
"catalog": catalog_name,
"row_index": row_idx + 1, # Index in Google Sheet
"status": "locked" if lock_info["is_locked"] else "free",
"locked_by": lock_info["locked_by"]
})
# return {"status": "success", "country": country, "catalogs": catalogs}
return {"status": "success", "country": country, "catalogs": catalogs}
# except Exception as e:
# traceback.print_exc()
# raise HTTPException(status_code=500, detail=str(e))
except Exception as e:
traceback.print_exc()
raise HTTPException(status_code=500, detail=str(e))
@app.get("/catalog/data/{country}/{catalog}/{user_id}")
def get_catalog_data(country: str, catalog: str, user_id: str, background_tasks: BackgroundTasks):