-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (40 loc) · 1.42 KB
/
main.py
File metadata and controls
47 lines (40 loc) · 1.42 KB
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
from stt import capture_dream
from da import analyze_emotions
from dreamart import draw_dream_art
import csv
import os
from datetime import datetime
import subprocess
# Step 1: Capture dream text
dream_text = capture_dream()
if not dream_text:
print("❌ No valid dream captured. Exiting.")
exit()
# Step 2: Analyze emotions + surrealism
emotions, surreal_score = analyze_emotions(dream_text)
# Step 3: Save to CSV
csv_file = "dream_diary.csv"
fieldnames = ["Date", "Dream", "Happy", "Angry", "Surprise", "Sad", "Fear", "Surrealism"]
new_row = {
"Date": datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
"Dream": dream_text,
"Happy": emotions["Happy"],
"Angry": emotions["Angry"],
"Surprise": emotions["Surprise"],
"Sad": emotions["Sad"],
"Fear": emotions["Fear"],
"Surrealism": surreal_score
}
# If file doesn't exist, write headers
file_exists = os.path.isfile(csv_file)
with open(csv_file, mode="a", newline="", encoding="utf-8") as file:
writer = csv.DictWriter(file, fieldnames=fieldnames)
if not file_exists:
writer.writeheader()
writer.writerow(new_row)
print(f"📄 Logged dream to {csv_file}.")
# Step 4: Draw the art
draw_dream_art(emotions, surreal_score)
subprocess.run(["xdg-open", "dream_art.png"]) # Open the generated art
subprocess.run(["xdg-open", "dream_diary.csv"]) # Open the CSV file
subprocess.call(["Rscript", "R_analysis.R"]) # Run R script for trend analysis