Spaces:
Sleeping
Sleeping
rsm-roguchi commited on
Commit ·
052fa72
1
Parent(s): 9ebfdb5
uh
Browse files- server/inventory.py +10 -9
server/inventory.py
CHANGED
|
@@ -44,23 +44,24 @@ def load_sheet_to_duckdb(spreadsheet_id, sheet_tab="Sheet1", table_name="active_
|
|
| 44 |
.execute()
|
| 45 |
.get("values", [])
|
| 46 |
)
|
| 47 |
-
|
| 48 |
if not values:
|
| 49 |
raise ValueError("Google Sheet is empty or not accessible.")
|
| 50 |
|
| 51 |
headers = values[0]
|
| 52 |
-
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
insert_cols = ", ".join(f'"{h}"' for h in headers)
|
| 57 |
|
| 58 |
-
con.
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
""
|
|
|
|
| 62 |
return con
|
| 63 |
|
|
|
|
| 64 |
sheet_index = {}
|
| 65 |
|
| 66 |
def server(input, output, session):
|
|
|
|
| 44 |
.execute()
|
| 45 |
.get("values", [])
|
| 46 |
)
|
|
|
|
| 47 |
if not values:
|
| 48 |
raise ValueError("Google Sheet is empty or not accessible.")
|
| 49 |
|
| 50 |
headers = values[0]
|
| 51 |
+
# pad rows to header length
|
| 52 |
+
rows = [r + [''] * (len(headers) - len(r)) for r in values[1:]]
|
| 53 |
|
| 54 |
+
# Build DataFrame (avoids all quoting issues)
|
| 55 |
+
df = pd.DataFrame(rows, columns=headers)
|
|
|
|
| 56 |
|
| 57 |
+
con = duckdb.connect()
|
| 58 |
+
# Register df and create/replace the table from it
|
| 59 |
+
con.register("temp_df", df)
|
| 60 |
+
con.execute(f'CREATE OR REPLACE TABLE "{table_name}" AS SELECT * FROM temp_df')
|
| 61 |
+
con.unregister("temp_df")
|
| 62 |
return con
|
| 63 |
|
| 64 |
+
|
| 65 |
sheet_index = {}
|
| 66 |
|
| 67 |
def server(input, output, session):
|