Spaces:
Sleeping
Sleeping
File size: 3,035 Bytes
d5ed357 2d98bc7 d5ed357 2d98bc7 d5ed357 2d98bc7 19017cb 2d98bc7 34f17d2 56f53e5 2d98bc7 d5ed357 2d98bc7 d5ed357 2d98bc7 126459d 2d98bc7 56e9ea6 d5ed357 56e9ea6 2d98bc7 56e9ea6 1496bf9 56e9ea6 2d98bc7 1496bf9 56e9ea6 2d98bc7 1a6b559 56f53e5 1a6b559 56f53e5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
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
}
@app.post("/video")
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)
@app.post("/image")
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)
@app.post("/registerContractor")
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)}
|