Spaces:
Runtime error
Runtime error
Download lead_client.py from buildbot5510/buildbot: direct link, hf CLI and curl.
- Browser
- Download file 2.13 kB
-
https://huggingface.co/spaces/buildbot5510/buildbot/resolve/main/lead_client.py
- Command line
-
hf download hf://spaces/buildbot5510/buildbot/lead_client.py
-
curl -L -o lead_client.py https://huggingface.co/spaces/buildbot5510/buildbot/resolve/main/lead_client.py
2.13 kB
| import os | |
| from dotenv import load_dotenv | |
| import requests | |
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| load_dotenv() # Load environment variables from .env file | |
| # π CONFIG | |
| BASEROW_TOKEN = "5WioOnzQce7V6ZS2smAjCOr3TEfXNBFM" | |
| LEAD_CLIENT_TABLE_ID = 914565 | |
| # if not BASEROW_TOKEN or not TABLE_ID: | |
| # raise Exception("β Missing BASEROW_TOKEN or TABLE_ID in environment variables") | |
| BASE_URL = f"https://api.baserow.io/api/database/rows/table/{LEAD_CLIENT_TABLE_ID}/" | |
| HEADERS = { | |
| "Authorization": f"Token {BASEROW_TOKEN}", | |
| "Content-Type": "application/json" | |
| } | |
| # π₯ Request Model | |
| class User(BaseModel): | |
| name: str | |
| mobile: str | |
| org: str | |
| # π Check if user exists (SAFE METHOD) | |
| def check_user_exists(mobile): | |
| try: | |
| response = requests.get(BASE_URL, headers=HEADERS) | |
| # print("\n--- CHECK USER DEBUG ---") | |
| # print("STATUS:", response.status_code) | |
| # print("RESPONSE:", response.text) | |
| if response.status_code == 200: | |
| data = response.json() | |
| for row in data.get("results", []): | |
| # β use field ID | |
| if str(row.get("field_7932385")) == str(mobile): | |
| return { | |
| "name": row.get("field_7932386"), | |
| "mobile": row.get("field_7932385"), | |
| "org": row.get("field_7968316") | |
| } | |
| return False | |
| except Exception as e: | |
| print("CHECK ERROR:", str(e)) | |
| return False | |
| # πΎ Save user to Baserow | |
| def save_user(name, mobile, orgId): | |
| payload = { | |
| "field_7932386": name, # β name | |
| "field_7932385": str(mobile), # β mobile | |
| "field_7968316": orgId # β organization ID | |
| } | |
| try: | |
| response = requests.post(BASE_URL, headers=HEADERS, json=payload) | |
| # print("\n--- SAVE USER DEBUG ---") | |
| # print("PAYLOAD:", payload) | |
| # print("STATUS:", response.status_code) | |
| # print("RESPONSE:", response.text) | |
| return response.status_code in [200, 201] | |
| except Exception as e: | |
| print("SAVE ERROR:", str(e)) | |
| return False | |