Skip to content

Commit bec865a

Browse files
committed
fix: apply user csv format
1 parent 6184bf4 commit bec865a

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

getcloser/backend/app/scripts/user_data_to_question.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,25 @@
77
rows = []
88
id_counter = 1
99

10-
with open(input_file, newline="", encoding="utf-8") as f:
10+
with open(input_file, newline="", encoding="utf-8-sig") as f:
1111
reader = csv.DictReader(f)
1212

1313
for row in reader:
1414
user_id = row["idx"]
15+
if user_id == "idx":
16+
# Skip duplicated header row in data.
17+
continue
1518

1619
# category 1: 관심사 키워드 (JSON 리스트)
17-
interests = json.loads(row["interest_keywords"])
20+
raw_interest_keywords = (row.get("interest_keywords") or "").strip()
21+
if raw_interest_keywords:
22+
try:
23+
interests = json.loads(raw_interest_keywords)
24+
except json.JSONDecodeError:
25+
# Fallback for non-JSON input like "a,b,c"
26+
interests = [value.strip() for value in raw_interest_keywords.split(",") if value.strip()]
27+
else:
28+
interests = []
1829
for interest in interests:
1930
rows.append([
2031
id_counter,

0 commit comments

Comments
 (0)