CocoonAI commited on
Commit
a8d2456
Β·
1 Parent(s): 04342ca

Update profile_writer.py

Browse files
Files changed (1) hide show
  1. profile_writer.py +31 -20
profile_writer.py CHANGED
@@ -1,42 +1,56 @@
1
  import os
 
 
2
 
3
- def write_file(user_path, relative_path, content):
 
 
 
 
4
  full_path = os.path.join(user_path, relative_path)
5
  os.makedirs(os.path.dirname(full_path), exist_ok=True)
 
6
  with open(full_path, "w", encoding="utf-8") as f:
7
  f.write(content.strip() + "\n")
8
 
 
 
 
 
 
 
 
9
  def write_profile_to_obsidian(user_id: str, data: dict, base_path=None):
10
  if base_path is None:
11
- base_path = os.path.join("/data", "vaults", f"user_{user_id}")
12
  os.makedirs(base_path, exist_ok=True)
13
  print(f"[WRITE] Creating Obsidian structure for user: {user_id} at {base_path}")
14
 
15
  # === Profile Folder ===
16
- write_file(base_path, "Profile/user_profile.md", f"""
17
  # πŸ‘€ User Profile
18
  - Experience Level: {data.get("experienceLevel", "")}
19
  - Main Goal: {data.get("contentGoal", "")}
20
  - Location: {data.get("country", "")}, {data.get("city", "")}
21
  """)
22
 
23
- write_file(base_path, "Profile/business_profile.md", f"""
24
  # 🏒 Business Profile
25
  - Type: {data.get("businessType", "")}
26
  - Description: {data.get("businessDescription", "")}
27
  - Niche: {data.get("niche", "")}
28
  """)
29
 
30
- write_file(base_path, "Profile/creator_personality.md", "# ✨ Creator Personality\nTo be discovered...")
31
 
32
  # === Content Strategy ===
33
- write_file(base_path, "Content_Strategy/content_goals.md", f"""
34
  # 🎯 Content Goals
35
  - Goal: {data.get("contentGoal", "")}
36
  - Niche: {data.get("niche", "")}
37
  """)
38
 
39
- write_file(base_path, "Content_Strategy/platforms_and_audience.md", f"""
40
  # πŸ“£ Platforms & Audience
41
  - Platforms: {", ".join(data.get("platforms", []))}
42
  - Target Generation: {data.get("targetGeneration", "")}
@@ -44,38 +58,35 @@ def write_profile_to_obsidian(user_id: str, data: dict, base_path=None):
44
  - Monetization Intent: {data.get("monetizationIntent", "")}
45
  """)
46
 
47
- write_file(base_path, "Content_Strategy/content_types_and_niche.md", f"""
48
  # πŸ“¦ Content Types & Niche
49
  - Types: {", ".join(data.get("contentTypes", []))}
50
  - Challenges: {data.get("mainChallenges", "")}
51
  """)
52
 
53
- write_file(base_path, "Content_Strategy/social_accounts.md", "# πŸ”— Social Accounts\nAdd your accounts here.")
54
 
55
  # === Resources & Skills ===
56
- write_file(base_path, "Resources_and_Skills/current_challenges.md", f"""
57
  # ❗ Current Challenges
58
  {data.get("mainChallenges", "")}
59
  """)
60
 
61
- write_file(base_path, "Resources_and_Skills/available_resources.md", f"""
62
  # πŸ› οΈ Available Resources
63
  {data.get("resources", "")}
64
  """)
65
 
66
- write_file(base_path, "Resources_and_Skills/learning_preferences.md", "# πŸ“š Learning Preferences\nTo define.")
67
-
68
- write_file(base_path, "Resources_and_Skills/existing_skills.md", "# πŸ’‘ Existing Skills\nList them here.")
69
 
70
  # === Goals & Metrics ===
71
- write_file(base_path, "Goals_and_Metrics/impact_goals.md", "# 🌍 Impact Goals\nTo define.")
72
-
73
- write_file(base_path, "Goals_and_Metrics/success_metrics.md", "# πŸ“ˆ Success Metrics\nTo define.")
74
-
75
- write_file(base_path, "Goals_and_Metrics/monetization_strategy.md", "# πŸ’° Monetization Strategy\nTo define.")
76
 
77
  # === AI Context ===
78
- write_file(base_path, "AI_Context/onboarding_summary.md", f"""
79
  # πŸ€– AI Onboarding Summary
80
  This file summarizes the user context.
81
 
 
1
  import os
2
+ from supabase import create_client
3
+ import json
4
 
5
+ SUPABASE_URL = os.getenv("SUPABASE_URL")
6
+ SUPABASE_KEY = os.getenv("SUPABASE_KEY")
7
+ supabase_client = create_client(SUPABASE_URL, SUPABASE_KEY)
8
+
9
+ def write_file(user_id, user_path, relative_path, content):
10
  full_path = os.path.join(user_path, relative_path)
11
  os.makedirs(os.path.dirname(full_path), exist_ok=True)
12
+
13
  with open(full_path, "w", encoding="utf-8") as f:
14
  f.write(content.strip() + "\n")
15
 
16
+ # Stocker aussi dans Supabase (table "vault_files")
17
+ supabase_client.table("vault_files").upsert({
18
+ "user_id": user_id,
19
+ "path": relative_path,
20
+ "content": content.strip()
21
+ }).execute()
22
+
23
  def write_profile_to_obsidian(user_id: str, data: dict, base_path=None):
24
  if base_path is None:
25
+ base_path = os.path.join(tempfile.gettempdir(), "vaults", f"user_{user_id}")
26
  os.makedirs(base_path, exist_ok=True)
27
  print(f"[WRITE] Creating Obsidian structure for user: {user_id} at {base_path}")
28
 
29
  # === Profile Folder ===
30
+ write_file(user_id, base_path, "Profile/user_profile.md", f"""
31
  # πŸ‘€ User Profile
32
  - Experience Level: {data.get("experienceLevel", "")}
33
  - Main Goal: {data.get("contentGoal", "")}
34
  - Location: {data.get("country", "")}, {data.get("city", "")}
35
  """)
36
 
37
+ write_file(user_id, base_path, "Profile/business_profile.md", f"""
38
  # 🏒 Business Profile
39
  - Type: {data.get("businessType", "")}
40
  - Description: {data.get("businessDescription", "")}
41
  - Niche: {data.get("niche", "")}
42
  """)
43
 
44
+ write_file(user_id, base_path, "Profile/creator_personality.md", "# ✨ Creator Personality\nTo be discovered...")
45
 
46
  # === Content Strategy ===
47
+ write_file(user_id, base_path, "Content_Strategy/content_goals.md", f"""
48
  # 🎯 Content Goals
49
  - Goal: {data.get("contentGoal", "")}
50
  - Niche: {data.get("niche", "")}
51
  """)
52
 
53
+ write_file(user_id, base_path, "Content_Strategy/platforms_and_audience.md", f"""
54
  # πŸ“£ Platforms & Audience
55
  - Platforms: {", ".join(data.get("platforms", []))}
56
  - Target Generation: {data.get("targetGeneration", "")}
 
58
  - Monetization Intent: {data.get("monetizationIntent", "")}
59
  """)
60
 
61
+ write_file(user_id, base_path, "Content_Strategy/content_types_and_niche.md", f"""
62
  # πŸ“¦ Content Types & Niche
63
  - Types: {", ".join(data.get("contentTypes", []))}
64
  - Challenges: {data.get("mainChallenges", "")}
65
  """)
66
 
67
+ write_file(user_id, base_path, "Content_Strategy/social_accounts.md", "# πŸ”— Social Accounts\nAdd your accounts here.")
68
 
69
  # === Resources & Skills ===
70
+ write_file(user_id, base_path, "Resources_and_Skills/current_challenges.md", f"""
71
  # ❗ Current Challenges
72
  {data.get("mainChallenges", "")}
73
  """)
74
 
75
+ write_file(user_id, base_path, "Resources_and_Skills/available_resources.md", f"""
76
  # πŸ› οΈ Available Resources
77
  {data.get("resources", "")}
78
  """)
79
 
80
+ write_file(user_id, base_path, "Resources_and_Skills/learning_preferences.md", "# πŸ“š Learning Preferences\nTo define.")
81
+ write_file(user_id, base_path, "Resources_and_Skills/existing_skills.md", "# πŸ’‘ Existing Skills\nList them here.")
 
82
 
83
  # === Goals & Metrics ===
84
+ write_file(user_id, base_path, "Goals_and_Metrics/impact_goals.md", "# 🌍 Impact Goals\nTo define.")
85
+ write_file(user_id, base_path, "Goals_and_Metrics/success_metrics.md", "# πŸ“ˆ Success Metrics\nTo define.")
86
+ write_file(user_id, base_path, "Goals_and_Metrics/monetization_strategy.md", "# πŸ’° Monetization Strategy\nTo define.")
 
 
87
 
88
  # === AI Context ===
89
+ write_file(user_id, base_path, "AI_Context/onboarding_summary.md", f"""
90
  # πŸ€– AI Onboarding Summary
91
  This file summarizes the user context.
92