yukee1992 commited on
Commit
0f15249
Β·
verified Β·
1 Parent(s): d44f790

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -47
app.py CHANGED
@@ -78,20 +78,17 @@ else:
78
  def create_project(title, content, tags, image_prompt, channel):
79
  """Create a new project and save to Supabase"""
80
  print(f"\nπŸ“ Creating project: {title}")
81
- print(f" Content length: {len(content)}")
82
- print(f" Tags: {tags}")
83
- print(f" Image prompt: {image_prompt[:30]}...")
84
 
85
  try:
86
- # Generate project data
87
- project_id = str(uuid.uuid4())[:8]
88
  folder_name = title.lower().replace(' ', '_').replace('/', '-')[:20]
89
 
90
  project_data = {
91
  "project_id": project_id,
92
  "folder_name": folder_name,
93
  "title": title,
94
- "content": content[:5000], # Limit content length
95
  "tags": tags,
96
  "image_prompt": image_prompt,
97
  "channel_details": channel,
@@ -99,57 +96,31 @@ def create_project(title, content, tags, image_prompt, channel):
99
  "created_at": datetime.now().isoformat()
100
  }
101
 
102
- print(f"πŸ“¦ Project data prepared: {project_id}")
103
 
104
- # Save to Supabase if connected
105
- db_result = None
106
  if supabase:
107
- try:
108
- print("πŸ’Ύ Attempting to save to Supabase...")
109
- result = supabase.table("projects").insert(project_data).execute()
110
- db_result = result.data[0] if result.data else None
111
- print(f"βœ… Successfully saved to Supabase! Record ID: {db_result.get('id') if db_result else 'unknown'}")
112
-
113
- return {
114
- "status": "success",
115
- "project_id": project_id,
116
- "folder": folder_name,
117
- "title": title,
118
- "message": "Project created and saved to database!",
119
- "database_id": db_result.get('id') if db_result else None,
120
- "timestamp": datetime.now().isoformat()
121
- }
122
-
123
- except Exception as e:
124
- print(f"❌ Supabase save failed: {e}")
125
- return {
126
- "status": "partial_success",
127
- "project_id": project_id,
128
- "folder": folder_name,
129
- "title": title,
130
- "message": f"Project created but database save failed: {str(e)}",
131
- "timestamp": datetime.now().isoformat()
132
- }
133
  else:
134
- print("⚠️ Supabase not connected - project only in memory")
135
  return {
136
  "status": "memory_only",
137
  "project_id": project_id,
138
  "folder": folder_name,
139
  "title": title,
140
- "message": "Project created in memory only (no database connection)",
141
- "timestamp": datetime.now().isoformat()
142
  }
143
-
144
  except Exception as e:
145
- print(f"❌ Error in create_project: {e}")
146
- import traceback
147
- traceback.print_exc()
148
- return {
149
- "status": "error",
150
- "message": f"Error: {str(e)}",
151
- "timestamp": datetime.now().isoformat()
152
- }
153
 
154
  def search_projects(term):
155
  """Search for projects in Supabase"""
 
78
  def create_project(title, content, tags, image_prompt, channel):
79
  """Create a new project and save to Supabase"""
80
  print(f"\nπŸ“ Creating project: {title}")
 
 
 
81
 
82
  try:
83
+ # Generate proper UUID
84
+ project_id = str(uuid.uuid4()) # Full UUID
85
  folder_name = title.lower().replace(' ', '_').replace('/', '-')[:20]
86
 
87
  project_data = {
88
  "project_id": project_id,
89
  "folder_name": folder_name,
90
  "title": title,
91
+ "content": content,
92
  "tags": tags,
93
  "image_prompt": image_prompt,
94
  "channel_details": channel,
 
96
  "created_at": datetime.now().isoformat()
97
  }
98
 
99
+ print(f"πŸ’Ύ Saving project with UUID: {project_id}")
100
 
 
 
101
  if supabase:
102
+ result = supabase.table("projects").insert(project_data).execute()
103
+ print("βœ… Saved to database")
104
+
105
+ return {
106
+ "status": "success",
107
+ "project_id": project_id,
108
+ "folder": folder_name,
109
+ "title": title,
110
+ "message": "Project created!"
111
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  else:
 
113
  return {
114
  "status": "memory_only",
115
  "project_id": project_id,
116
  "folder": folder_name,
117
  "title": title,
118
+ "message": "No database connection"
 
119
  }
120
+
121
  except Exception as e:
122
+ print(f"❌ Error: {e}")
123
+ return {"status": "error", "message": str(e)}
 
 
 
 
 
 
124
 
125
  def search_projects(term):
126
  """Search for projects in Supabase"""