Update crs_arena/utils.py
Browse files- crs_arena/utils.py +22 -10
crs_arena/utils.py
CHANGED
@@ -145,16 +145,28 @@ async def upload_feedback_to_gsheet(
|
|
145 |
"""
|
146 |
logging.debug("Uploading feedback to Google Sheets.")
|
147 |
try:
|
148 |
-
|
149 |
-
|
150 |
)
|
151 |
-
df = gs_connection.read(worksheet=worksheet)
|
152 |
-
if df[df["id"] == row["id"]].empty:
|
153 |
-
df = pd.concat([df, pd.DataFrame([row])], ignore_index=True)
|
154 |
-
else:
|
155 |
-
# Add feedback to existing row
|
156 |
-
df.loc[df["id"] == row["id"], "feedback"] = row["feedback"]
|
157 |
-
gs_connection.update(data=df, worksheet=worksheet)
|
158 |
-
logging.debug("Feedback uploaded to Google Sheets.")
|
159 |
except Exception as e:
|
160 |
logging.error(f"Error uploading feedback to Google Sheets: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
"""
|
146 |
logging.debug("Uploading feedback to Google Sheets.")
|
147 |
try:
|
148 |
+
await asyncio.get_event_loop().run_in_executor(
|
149 |
+
None, lambda: _upload_feedback_to_gsheet_sync(row, worksheet)
|
150 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
except Exception as e:
|
152 |
logging.error(f"Error uploading feedback to Google Sheets: {e}")
|
153 |
+
|
154 |
+
|
155 |
+
def _upload_feedback_to_gsheet_sync(
|
156 |
+
row: Dict[str, str], worksheet: str
|
157 |
+
) -> None:
|
158 |
+
"""Uploads feedback to Google Sheets synchronously.
|
159 |
+
|
160 |
+
Args:
|
161 |
+
row: Row to upload to the worksheet.
|
162 |
+
worksheet: Name of the worksheet to upload the feedback to.
|
163 |
+
"""
|
164 |
+
gs_connection = st.connection("gsheets", type=GSheetsConnection)
|
165 |
+
df = gs_connection.read(worksheet=worksheet)
|
166 |
+
if df[df["id"] == row["id"]].empty:
|
167 |
+
df = pd.concat([df, pd.DataFrame([row])], ignore_index=True)
|
168 |
+
else:
|
169 |
+
# Add feedback to existing row
|
170 |
+
df.loc[df["id"] == row["id"], "feedback"] = row["feedback"]
|
171 |
+
gs_connection.update(data=df, worksheet=worksheet)
|
172 |
+
logging.debug("Feedback uploaded to Google Sheets.")
|