Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI, Request | |
| import requests | |
| app = FastAPI() | |
| # Constants | |
| ACCESS_TOKEN = "2585415_877e3999ec927cff5d896269c348106949c50f9b8ad54fdaeac07ad00687ce3e" | |
| TEAM_ID = "9018441024" | |
| # Video Contractor Settings | |
| VIDEO_FOLDER_ID = "90182650380" | |
| VIDEO_TEMPLATE_ID = "t-901804880155" | |
| # Image Contractor Settings | |
| IMAGE_FOLDER_ID = "90182896356" | |
| IMAGE_TEMPLATE_ID = "t-901809661788" | |
| GOOGLE_SHEET_WEBHOOK = "https://script.google.com/macros/s/AKfycbw7Ognf2qKo-nhlVsiQkbb21vYqNp6VV3IfriBadQ06--x2VYn7KZIQuKRW9BPyjmGO/exec" | |
| def create_list_from_template(folder_id, template_id, list_name): | |
| url = f"https://api.clickup.com/api/v2/folder/{folder_id}/list_template/{template_id}" | |
| headers = { | |
| "Authorization": ACCESS_TOKEN, | |
| "Content-Type": "application/json" | |
| } | |
| payload = { | |
| "name": list_name, | |
| "options": { | |
| "return_immediately": True | |
| } | |
| } | |
| response = requests.post(url, headers=headers, json=payload) | |
| if response.status_code == 200: | |
| result = response.json() | |
| list_id = result.get("id") | |
| list_url = f"https://app.clickup.com/{TEAM_ID}/v/li/{list_id}" | |
| return {"message": "β List created successfully.", "list_url": list_url} | |
| else: | |
| return { | |
| "message": "β Failed to create list.", | |
| "status_code": response.status_code, | |
| "error": response.text | |
| } | |
| async def create_video_contractor_list(request: Request): | |
| data = await request.json() | |
| list_name = data.get("listName") | |
| if not list_name: | |
| return {"error": "Missing 'listName' in request"} | |
| return create_list_from_template(VIDEO_FOLDER_ID, VIDEO_TEMPLATE_ID, list_name) | |
| async def create_image_contractor_list(request: Request): | |
| data = await request.json() | |
| list_name = data.get("listName") | |
| if not list_name: | |
| return {"error": "Missing 'listName' in request"} | |
| return create_list_from_template(IMAGE_FOLDER_ID, IMAGE_TEMPLATE_ID, list_name) | |
| async def register_contractor(request: Request): | |
| data = await request.json() | |
| print("π₯ Received contractor data from content.js:", data) | |
| name = data.get("contractorName") | |
| email = data.get("contractorEmail") | |
| contractor_type = data.get("contractorType") | |
| if not name or not email or not contractor_type: | |
| return {"error": "Missing one or more required fields"} | |
| sheet_payload = { | |
| "name": name, | |
| "email": email, | |
| "type": contractor_type | |
| } | |
| try: | |
| sheet_response = requests.post(GOOGLE_SHEET_WEBHOOK, json=sheet_payload) | |
| print("π€ Sent to Google Sheet:", sheet_payload) | |
| return { | |
| "message": "β Contractor registered and sent to sheet.", | |
| "sheet_response": sheet_response.json() | |
| } | |
| except Exception as e: | |
| print("β Failed to send to Google Sheet:", str(e)) | |
| return {"error": "Failed to send to sheet", "details": str(e)} | |