Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -6,6 +6,7 @@ app = FastAPI()
|
|
| 6 |
# Constants
|
| 7 |
ACCESS_TOKEN = "2585415_877e3999ec927cff5d896269c348106949c50f9b8ad54fdaeac07ad00687ce3e"
|
| 8 |
TEAM_ID = "9018441024"
|
|
|
|
| 9 |
|
| 10 |
# Video Contractor Settings
|
| 11 |
VIDEO_FOLDER_ID = "90182650380"
|
|
@@ -34,31 +35,52 @@ def create_list_from_template(folder_id, template_id, list_name):
|
|
| 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 {"
|
| 38 |
else:
|
| 39 |
-
return {
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 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 |
-
|
| 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 |
-
|
| 62 |
-
return {"error": "Missing 'listName' in request"}
|
| 63 |
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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"
|
|
|
|
| 35 |
result = response.json()
|
| 36 |
list_id = result.get("id")
|
| 37 |
list_url = f"https://app.clickup.com/{TEAM_ID}/v/li/{list_id}"
|
| 38 |
+
return {"success": True, "list_url": list_url}
|
| 39 |
else:
|
| 40 |
+
return {"success": False, "status_code": response.status_code, "error": response.text}
|
| 41 |
+
|
| 42 |
+
def send_to_google_sheet(name, email, contractor_type):
|
| 43 |
+
payload = {
|
| 44 |
+
"name": name,
|
| 45 |
+
"email": email,
|
| 46 |
+
"type": contractor_type
|
| 47 |
+
}
|
| 48 |
+
try:
|
| 49 |
+
sheet_response = requests.post(GOOGLE_SHEET_WEBHOOK, json=payload)
|
| 50 |
+
return sheet_response.json()
|
| 51 |
+
except Exception as e:
|
| 52 |
+
return {"error": str(e)}
|
| 53 |
|
| 54 |
@app.post("/video")
|
| 55 |
async def create_video_contractor_list(request: Request):
|
| 56 |
data = await request.json()
|
| 57 |
list_name = data.get("listName")
|
| 58 |
+
email = data.get("email")
|
| 59 |
|
| 60 |
+
if not list_name or not email:
|
| 61 |
+
return {"error": "Missing 'listName' or 'email' in request"}
|
| 62 |
|
| 63 |
+
result = create_list_from_template(VIDEO_FOLDER_ID, VIDEO_TEMPLATE_ID, list_name)
|
| 64 |
|
| 65 |
+
if result.get("success"):
|
| 66 |
+
sheet_result = send_to_google_sheet(list_name, email, "video")
|
| 67 |
+
return {"list_url": result.get("list_url"), "sheet_result": sheet_result}
|
| 68 |
+
else:
|
| 69 |
+
return result
|
| 70 |
|
| 71 |
@app.post("/image")
|
| 72 |
async def create_image_contractor_list(request: Request):
|
| 73 |
data = await request.json()
|
| 74 |
list_name = data.get("listName")
|
| 75 |
+
email = data.get("email")
|
| 76 |
+
|
| 77 |
+
if not list_name or not email:
|
| 78 |
+
return {"error": "Missing 'listName' or 'email' in request"}
|
| 79 |
|
| 80 |
+
result = create_list_from_template(IMAGE_FOLDER_ID, IMAGE_TEMPLATE_ID, list_name)
|
|
|
|
| 81 |
|
| 82 |
+
if result.get("success"):
|
| 83 |
+
sheet_result = send_to_google_sheet(list_name, email, "image")
|
| 84 |
+
return {"list_url": result.get("list_url"), "sheet_result": sheet_result}
|
| 85 |
+
else:
|
| 86 |
+
return result
|