Auto-update: Mon Oct 28 12:22:39 PDT 2024
This commit is contained in:
parent
f9be743dfd
commit
3bc44477ba
1 changed files with 29 additions and 8 deletions
|
@ -589,21 +589,42 @@ async def ensure_project_exists(project_name: str) -> str:
|
||||||
# First check if project exists
|
# First check if project exists
|
||||||
async with httpx.AsyncClient() as client:
|
async with httpx.AsyncClient() as client:
|
||||||
response = await client.get(url, headers=headers)
|
response = await client.get(url, headers=headers)
|
||||||
|
if response.status_code != 200:
|
||||||
|
l.error(f"Project list response: {response.text}")
|
||||||
|
raise HTTPException(status_code=response.status_code, detail=response.text)
|
||||||
|
|
||||||
projects = response.json().get('data', [])
|
projects = response.json().get('data', [])
|
||||||
|
|
||||||
|
# Debug log to see what we're getting
|
||||||
|
l.debug(f"Found projects: {json.dumps(projects, indent=2)}")
|
||||||
|
|
||||||
for project in projects:
|
for project in projects:
|
||||||
if project['title'] == project_name:
|
project_title = project.get('attributes', {}).get('title')
|
||||||
return project['id']
|
if project_title == project_name:
|
||||||
|
return project.get('id') # or project.get('attributes', {}).get('id')
|
||||||
|
|
||||||
# Project doesn't exist, create it
|
# Project doesn't exist, create it
|
||||||
project_data = {
|
project_data = {
|
||||||
|
"data": {
|
||||||
|
"type": "projects",
|
||||||
|
"attributes": {
|
||||||
"title": project_name,
|
"title": project_name,
|
||||||
"color": "#007AFF", # Nice blue color for phone calls
|
"color": "#007AFF",
|
||||||
"icon": "📞"
|
"icon": "📞"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
l.debug(f"Creating project with data: {json.dumps(project_data, indent=2)}")
|
||||||
response = await client.post(url, headers=headers, json=project_data)
|
response = await client.post(url, headers=headers, json=project_data)
|
||||||
return response.json()['data']['id']
|
l.debug(f"Create project response: {response.text}")
|
||||||
|
|
||||||
|
if response.status_code != 201:
|
||||||
|
raise HTTPException(status_code=response.status_code, detail=response.text)
|
||||||
|
|
||||||
|
created_project = response.json().get('data', {})
|
||||||
|
return created_project.get('id')
|
||||||
|
|
||||||
|
|
||||||
@timing.post("/time/att_csv")
|
@timing.post("/time/att_csv")
|
||||||
async def process_att_csv(
|
async def process_att_csv(
|
||||||
|
@ -615,14 +636,14 @@ async def process_att_csv(
|
||||||
cleaned_lookup = load_phone_lookup()
|
cleaned_lookup = load_phone_lookup()
|
||||||
|
|
||||||
# Ensure the Phone Calls project exists
|
# Ensure the Phone Calls project exists
|
||||||
project_name = "📞 Phone Calls"
|
project_name = "📞 Phone Calls" # This is correct
|
||||||
try:
|
try:
|
||||||
project_id = await ensure_project_exists(project_name)
|
project_id = await ensure_project_exists(project_name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
l.error(f"Failed to ensure project exists: {e}")
|
l.error(f"Failed to ensure project exists: {e}")
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=500,
|
status_code=500,
|
||||||
detail="Failed to create or find Phone Calls project"
|
detail=f"Failed to create or find project '{project_name}'" # Fixed error message
|
||||||
)
|
)
|
||||||
|
|
||||||
# Read and process the CSV
|
# Read and process the CSV
|
||||||
|
|
Loading…
Reference in a new issue