Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -6,7 +6,6 @@ app = FastAPI()
|
|
| 6 |
# Constants
|
| 7 |
ACCESS_TOKEN = "2585415_877e3999ec927cff5d896269c348106949c50f9b8ad54fdaeac07ad00687ce3e"
|
| 8 |
TEAM_ID = "9018441024"
|
| 9 |
-
GOOGLE_SHEET_WEBHOOK = "https://script.google.com/macros/s/AKfycbwOqg1PNYyHTh8OfiaHy1ROY0GI3s5Emf4SYA7eiNz-vPrKNwS3CBZsI_vhzTM8KDfm/exec"
|
| 10 |
|
| 11 |
# Video Contractor Settings
|
| 12 |
VIDEO_FOLDER_ID = "90182650380"
|
|
@@ -29,71 +28,37 @@ def create_list_from_template(folder_id, template_id, list_name):
|
|
| 29 |
}
|
| 30 |
}
|
| 31 |
|
| 32 |
-
print(f"π¦ Sending ClickUp list creation request: {payload}")
|
| 33 |
-
|
| 34 |
response = requests.post(url, headers=headers, json=payload)
|
| 35 |
-
print(f"π¨ ClickUp response status: {response.status_code}")
|
| 36 |
-
print(f"π¨ ClickUp response body: {response.text}")
|
| 37 |
|
| 38 |
if response.status_code == 200:
|
| 39 |
result = response.json()
|
| 40 |
list_id = result.get("id")
|
| 41 |
list_url = f"https://app.clickup.com/{TEAM_ID}/v/li/{list_id}"
|
| 42 |
-
return {"
|
| 43 |
else:
|
| 44 |
-
return {
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
"email": email,
|
| 50 |
-
"type": contractor_type
|
| 51 |
-
}
|
| 52 |
-
print(f"π€ Sending data to Google Sheet: {payload}")
|
| 53 |
-
try:
|
| 54 |
-
sheet_response = requests.post(GOOGLE_SHEET_WEBHOOK, json=payload)
|
| 55 |
-
print(f"π₯ Google Sheet response status: {sheet_response.status_code}")
|
| 56 |
-
print(f"π₯ Google Sheet response body: {sheet_response.text}")
|
| 57 |
-
return sheet_response.json()
|
| 58 |
-
except Exception as e:
|
| 59 |
-
print(f"β Error sending to Google Sheet: {e}")
|
| 60 |
-
return {"error": str(e)}
|
| 61 |
|
| 62 |
@app.post("/video")
|
| 63 |
async def create_video_contractor_list(request: Request):
|
| 64 |
data = await request.json()
|
| 65 |
-
print(data)
|
| 66 |
list_name = data.get("listName")
|
| 67 |
-
email = data.get("email")
|
| 68 |
|
| 69 |
-
|
|
|
|
| 70 |
|
| 71 |
-
|
| 72 |
-
return {"error": "Missing 'listName' or 'email' in request"}
|
| 73 |
|
| 74 |
-
result = create_list_from_template(VIDEO_FOLDER_ID, VIDEO_TEMPLATE_ID, list_name)
|
| 75 |
-
|
| 76 |
-
if result.get("success"):
|
| 77 |
-
sheet_result = send_to_google_sheet(list_name, email, "video")
|
| 78 |
-
return {"list_url": result.get("list_url"), "sheet_result": sheet_result}
|
| 79 |
-
else:
|
| 80 |
-
return result
|
| 81 |
|
| 82 |
@app.post("/image")
|
| 83 |
async def create_image_contractor_list(request: Request):
|
| 84 |
data = await request.json()
|
| 85 |
list_name = data.get("listName")
|
| 86 |
-
email = data.get("email")
|
| 87 |
-
|
| 88 |
-
print(f"π¨ /image endpoint called with: name={list_name}, email={email}")
|
| 89 |
|
| 90 |
-
if not list_name
|
| 91 |
-
return {"error": "Missing 'listName'
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
if result.get("success"):
|
| 96 |
-
sheet_result = send_to_google_sheet(list_name, email, "image")
|
| 97 |
-
return {"list_url": result.get("list_url"), "sheet_result": sheet_result}
|
| 98 |
-
else:
|
| 99 |
-
return result
|
|
|
|
| 6 |
# Constants
|
| 7 |
ACCESS_TOKEN = "2585415_877e3999ec927cff5d896269c348106949c50f9b8ad54fdaeac07ad00687ce3e"
|
| 8 |
TEAM_ID = "9018441024"
|
|
|
|
| 9 |
|
| 10 |
# Video Contractor Settings
|
| 11 |
VIDEO_FOLDER_ID = "90182650380"
|
|
|
|
| 28 |
}
|
| 29 |
}
|
| 30 |
|
|
|
|
|
|
|
| 31 |
response = requests.post(url, headers=headers, json=payload)
|
|
|
|
|
|
|
| 32 |
|
| 33 |
if response.status_code == 200:
|
| 34 |
result = response.json()
|
| 35 |
list_id = result.get("id")
|
| 36 |
list_url = f"https://app.clickup.com/{TEAM_ID}/v/li/{list_id}"
|
| 37 |
+
return {"message": "β
List created successfully.", "list_url": list_url}
|
| 38 |
else:
|
| 39 |
+
return {
|
| 40 |
+
"message": "β Failed to create list.",
|
| 41 |
+
"status_code": response.status_code,
|
| 42 |
+
"error": response.text
|
| 43 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
@app.post("/video")
|
| 46 |
async def create_video_contractor_list(request: Request):
|
| 47 |
data = await request.json()
|
|
|
|
| 48 |
list_name = data.get("listName")
|
|
|
|
| 49 |
|
| 50 |
+
if not list_name:
|
| 51 |
+
return {"error": "Missing 'listName' in request"}
|
| 52 |
|
| 53 |
+
return create_list_from_template(VIDEO_FOLDER_ID, VIDEO_TEMPLATE_ID, list_name)
|
|
|
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
@app.post("/image")
|
| 57 |
async def create_image_contractor_list(request: Request):
|
| 58 |
data = await request.json()
|
| 59 |
list_name = data.get("listName")
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
if not list_name:
|
| 62 |
+
return {"error": "Missing 'listName' in request"}
|
| 63 |
|
| 64 |
+
return create_list_from_template(IMAGE_FOLDER_ID, IMAGE_TEMPLATE_ID, list_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|