Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -15,6 +15,8 @@ VIDEO_TEMPLATE_ID = "t-901804880155"
|
|
| 15 |
IMAGE_FOLDER_ID = "90182896356"
|
| 16 |
IMAGE_TEMPLATE_ID = "t-901805178757"
|
| 17 |
|
|
|
|
|
|
|
| 18 |
def create_list_from_template(folder_id, template_id, list_name):
|
| 19 |
url = f"https://api.clickup.com/api/v2/folder/{folder_id}/list_template/{template_id}"
|
| 20 |
headers = {
|
|
@@ -63,8 +65,33 @@ async def create_image_contractor_list(request: Request):
|
|
| 63 |
|
| 64 |
return create_list_from_template(IMAGE_FOLDER_ID, IMAGE_TEMPLATE_ID, list_name)
|
| 65 |
|
|
|
|
| 66 |
@app.post("/registerContractor")
|
| 67 |
async def register_contractor(request: Request):
|
| 68 |
data = await request.json()
|
| 69 |
print("📥 Received contractor data from content.js:", data)
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
IMAGE_FOLDER_ID = "90182896356"
|
| 16 |
IMAGE_TEMPLATE_ID = "t-901805178757"
|
| 17 |
|
| 18 |
+
GOOGLE_SHEET_WEBHOOK = "https://script.google.com/macros/s/AKfycbwOqg1PNYyHTh8OfiaHy1ROY0GI3s5Emf4SYA7eiNz-vPrKNwS3CBZsI_vhzTM8KDfm/exec"
|
| 19 |
+
|
| 20 |
def create_list_from_template(folder_id, template_id, list_name):
|
| 21 |
url = f"https://api.clickup.com/api/v2/folder/{folder_id}/list_template/{template_id}"
|
| 22 |
headers = {
|
|
|
|
| 65 |
|
| 66 |
return create_list_from_template(IMAGE_FOLDER_ID, IMAGE_TEMPLATE_ID, list_name)
|
| 67 |
|
| 68 |
+
|
| 69 |
@app.post("/registerContractor")
|
| 70 |
async def register_contractor(request: Request):
|
| 71 |
data = await request.json()
|
| 72 |
print("📥 Received contractor data from content.js:", data)
|
| 73 |
+
|
| 74 |
+
name = data.get("contractorName")
|
| 75 |
+
email = data.get("contractorEmail")
|
| 76 |
+
contractor_type = data.get("contractorType")
|
| 77 |
+
|
| 78 |
+
if not name or not email or not contractor_type:
|
| 79 |
+
return {"error": "Missing one or more required fields"}
|
| 80 |
+
|
| 81 |
+
sheet_payload = {
|
| 82 |
+
"name": name,
|
| 83 |
+
"email": email,
|
| 84 |
+
"type": contractor_type
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
try:
|
| 88 |
+
sheet_response = requests.post(GOOGLE_SHEET_WEBHOOK, json=sheet_payload)
|
| 89 |
+
print("📤 Sent to Google Sheet:", sheet_payload)
|
| 90 |
+
return {
|
| 91 |
+
"message": "✅ Contractor registered and sent to sheet.",
|
| 92 |
+
"sheet_response": sheet_response.json()
|
| 93 |
+
}
|
| 94 |
+
except Exception as e:
|
| 95 |
+
print("❌ Failed to send to Google Sheet:", str(e))
|
| 96 |
+
return {"error": "Failed to send to sheet", "details": str(e)}
|
| 97 |
+
|