benjamin5607 commited on
Commit
357ec59
·
verified ·
1 Parent(s): 7a319d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -32
app.py CHANGED
@@ -41,7 +41,7 @@ st.markdown("""
41
  """, unsafe_allow_html=True)
42
 
43
  # ==========================================
44
- # 💾 2. 데이터 로드 (과잉 포장 제거 수술 완료)
45
  # ==========================================
46
  PLACE_DB = {}
47
  DUMMY_DATA = {
@@ -58,12 +58,8 @@ try:
58
  df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
59
  df = df.fillna("")
60
  df.columns = df.columns.str.strip()
61
-
62
- # [핵심 수정] json.dumps가 알아서 하므로 여기서 따옴표 강제 치환을 하지 않습니다.
63
- # 줄바꿈 문자만 공백으로 처리합니다.
64
  for col in df.select_dtypes(include=['object']).columns:
65
  df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True)
66
-
67
  if 'Country' in df.columns:
68
  df['Country'] = df['Country'].astype(str).str.strip()
69
  for country, group in df.groupby('Country'):
@@ -85,7 +81,7 @@ db_json_str = json.dumps(PLACE_DB, ensure_ascii=False)
85
  db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
86
 
87
  # ==========================================
88
- # 🖥️ 3. 통합 프론트엔드 (스탬프 로직 정상화)
89
  # ==========================================
90
  html_template = """
91
  <!DOCTYPE html>
@@ -112,7 +108,12 @@ html_template = """
112
  .type-btn.selected { background: var(--gold); color: black; border-color: var(--gold); }
113
 
114
  .place-list-container { flex: 1; overflow-y: auto; padding: 0 20px 120px 20px; }
115
- .place-card { background: #161616; border: 1px solid #2a2a2a; border-radius: 18px; padding: 20px; margin-bottom: 15px; position: relative; }
 
 
 
 
 
116
  .pc-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
117
  .pc-name { font-size: 18px; font-weight: bold; color: var(--gold); flex: 1; }
118
  .pc-dist { font-size: 12px; color: #888; font-weight: normal; margin-left: 5px; }
@@ -144,6 +145,8 @@ html_template = """
144
  .reco-btn { display: block; margin-top: 8px; padding: 10px; background: var(--gold); color: black !important; border-radius: 10px; font-weight: bold; text-decoration: none; font-size: 12px; cursor: pointer; border:none; width: 100%; text-align: center; }
145
  .popup-btn { background: var(--gold); color: black; border: none; padding: 6px 12px; border-radius: 5px; font-weight: bold; font-size: 11px; cursor: pointer; width: 100%; margin-top: 5px; }
146
  .leaflet-popup-content-wrapper { background: #1a1a1a; color: white; border: 1px solid var(--gold); }
 
 
147
  .stamp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; padding: 20px; }
148
  .stamp { height: 90px; border-radius: 15px; border: 2px dashed #333; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 10px; color: #444; background: #161625; }
149
  .stamp.active { border: 2px solid var(--gold); color: var(--gold); background: rgba(212,175,55,0.05); }
@@ -284,7 +287,12 @@ html_template = """
284
  const t = TRANSLATIONS[currentLang];
285
 
286
  filtered.forEach(p => {
287
- const card = document.createElement('div'); card.className = 'place-card';
 
 
 
 
 
288
  const displayLabel = p.label || p.category || "";
289
  const desc = p['desc_'+currentLang.toLowerCase()] || p.desc_ko || "";
290
  let distHtml = "";
@@ -293,11 +301,12 @@ html_template = """
293
  distHtml = `<span class="pc-dist">(📍 ${dist}km)</span>`;
294
  }
295
  card.innerHTML = `
 
296
  <div class="pc-header"><div class="pc-name">${p.name} ${distHtml}</div><div class="pc-label">${displayLabel}</div></div>
297
  <div class="pc-desc">${desc}</div>
298
  <div style="display:flex; gap:10px; margin-top:15px;">
299
  <button class="btn-action" style="background:var(--gold); color:black;" onclick="openReview('${p.name.replace(/'/g, "\\\\'")}', '${selectedCountry}')">${t.aiBtn}</button>
300
- <button class="btn-action" style="background:#333; color:white;" onclick="markVisited('${p.name.replace(/'/g, "\\\\'")}')">${t.mapBtn}</button>
301
  </div>`;
302
  list.appendChild(card);
303
  });
@@ -392,7 +401,6 @@ html_template = """
392
  box.appendChild(div); box.scrollTop = box.scrollHeight;
393
  }
394
 
395
- // [핵심] 스탬프 저장 로직 (따옴표 문제 해결됨)
396
  function markVisited(name) {
397
  let vp = JSON.parse(localStorage.getItem('visitedPlaces') || '[]');
398
  if(!vp.includes(name)) {
@@ -400,24 +408,35 @@ html_template = """
400
  localStorage.setItem('visitedPlaces', JSON.stringify(vp));
401
  visitedPlaces = vp;
402
  alert("✈️ Stamped on Passport!");
 
403
  } else { alert("You already visited here!"); }
404
  }
405
 
406
- // [핵심] 여권 열 때 데이터 새로고침
407
  function openPassport() {
408
  document.getElementById('passport-page').style.transform = 'translateX(0%)';
409
  visitedPlaces = JSON.parse(localStorage.getItem('visitedPlaces') || '[]');
410
-
411
  const grid = document.getElementById('stamp-grid');
412
  grid.innerHTML = "";
413
 
 
 
 
 
 
 
 
 
 
 
414
  for(let c in PLACE_DB) {
415
  PLACE_DB[c].forEach(p => {
416
- const active = visitedPlaces.includes(p.name);
417
- const div = document.createElement('div');
418
- div.className = 'stamp' + (active ? ' active' : '');
419
- div.innerHTML = active ? `🍷<br><b>${p.name}</b>` : `✈️`;
420
- grid.appendChild(div);
 
421
  });
422
  }
423
  }
@@ -433,7 +452,6 @@ html_template = """
433
  const lbl = p.label || p.category || "";
434
  const desc = p['desc_'+currentLang.toLowerCase()] || p.desc_ko || "";
435
  const shortDesc = desc.length > 50 ? desc.substring(0, 50) + "..." : desc;
436
-
437
  const popupContent = `
438
  <div style="text-align:left;">
439
  <b style="color:#d4af37; font-size:14px;">${p.name}</b><br>
@@ -456,24 +474,12 @@ html_template = """
456
  function searchMap() {
457
  const q = document.getElementById('map-input').value.toLowerCase();
458
  if(!q) return;
459
-
460
  let found = false;
461
  for(let c in PLACE_DB) {
462
- if(c.toLowerCase().includes(q)) {
463
- if(PLACE_DB[c].length > 0 && PLACE_DB[c][0].lat && PLACE_DB[c][0].lon) {
464
- worldMap.setView([PLACE_DB[c][0].lat, PLACE_DB[c][0].lon], 12);
465
- found = true; break;
466
- }
467
- }
468
  for(let p of PLACE_DB[c]) {
469
  const content = (p.name + " " + (p.address||"") + " " + (p.desc_ko||"")).toLowerCase();
470
- if(content.includes(q)) {
471
- if(p.lat && p.lon) {
472
- worldMap.setView([p.lat, p.lon], 16);
473
- L.popup().setLatLng([p.lat, p.lon]).setContent(`<b>${p.name}</b>`).openOn(worldMap);
474
- found = true; break;
475
- }
476
- }
477
  }
478
  if(found) break;
479
  }
 
41
  """, unsafe_allow_html=True)
42
 
43
  # ==========================================
44
+ # 💾 2. 데이터 로드 (유지)
45
  # ==========================================
46
  PLACE_DB = {}
47
  DUMMY_DATA = {
 
58
  df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
59
  df = df.fillna("")
60
  df.columns = df.columns.str.strip()
 
 
 
61
  for col in df.select_dtypes(include=['object']).columns:
62
  df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True)
 
63
  if 'Country' in df.columns:
64
  df['Country'] = df['Country'].astype(str).str.strip()
65
  for country, group in df.groupby('Country'):
 
81
  db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
82
 
83
  # ==========================================
84
+ # 🖥️ 3. 통합 프론트엔드 (여권 정렬 로직 수정)
85
  # ==========================================
86
  html_template = """
87
  <!DOCTYPE html>
 
108
  .type-btn.selected { background: var(--gold); color: black; border-color: var(--gold); }
109
 
110
  .place-list-container { flex: 1; overflow-y: auto; padding: 0 20px 120px 20px; }
111
+ .place-card { background: #161616; border: 1px solid #2a2a2a; border-radius: 18px; padding: 20px; margin-bottom: 15px; position: relative; transition: all 0.3s; }
112
+
113
+ .place-card.visited { border: 2px solid var(--gold); box-shadow: 0 0 15px rgba(212, 175, 55, 0.2); }
114
+ .visited-badge { position: absolute; top: -10px; right: -10px; background: var(--gold); color: black; font-weight: bold; padding: 5px 10px; border-radius: 15px; font-size: 10px; box-shadow: 0 2px 5px rgba(0,0,0,0.5); z-index: 10; animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
115
+ @keyframes popIn { from { transform: scale(0); } to { transform: scale(1); } }
116
+
117
  .pc-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
118
  .pc-name { font-size: 18px; font-weight: bold; color: var(--gold); flex: 1; }
119
  .pc-dist { font-size: 12px; color: #888; font-weight: normal; margin-left: 5px; }
 
145
  .reco-btn { display: block; margin-top: 8px; padding: 10px; background: var(--gold); color: black !important; border-radius: 10px; font-weight: bold; text-decoration: none; font-size: 12px; cursor: pointer; border:none; width: 100%; text-align: center; }
146
  .popup-btn { background: var(--gold); color: black; border: none; padding: 6px 12px; border-radius: 5px; font-weight: bold; font-size: 11px; cursor: pointer; width: 100%; margin-top: 5px; }
147
  .leaflet-popup-content-wrapper { background: #1a1a1a; color: white; border: 1px solid var(--gold); }
148
+ .leaflet-popup-content { margin: 10px; }
149
+
150
  .stamp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; padding: 20px; }
151
  .stamp { height: 90px; border-radius: 15px; border: 2px dashed #333; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 10px; color: #444; background: #161625; }
152
  .stamp.active { border: 2px solid var(--gold); color: var(--gold); background: rgba(212,175,55,0.05); }
 
287
  const t = TRANSLATIONS[currentLang];
288
 
289
  filtered.forEach(p => {
290
+ const isVisited = visitedPlaces.includes(p.name);
291
+ const visitedClass = isVisited ? ' visited' : '';
292
+ const visitedBadge = isVisited ? '<div class="visited-badge">🏆 VISITED</div>' : '';
293
+
294
+ const card = document.createElement('div');
295
+ card.className = 'place-card' + visitedClass;
296
  const displayLabel = p.label || p.category || "";
297
  const desc = p['desc_'+currentLang.toLowerCase()] || p.desc_ko || "";
298
  let distHtml = "";
 
301
  distHtml = `<span class="pc-dist">(📍 ${dist}km)</span>`;
302
  }
303
  card.innerHTML = `
304
+ ${visitedBadge}
305
  <div class="pc-header"><div class="pc-name">${p.name} ${distHtml}</div><div class="pc-label">${displayLabel}</div></div>
306
  <div class="pc-desc">${desc}</div>
307
  <div style="display:flex; gap:10px; margin-top:15px;">
308
  <button class="btn-action" style="background:var(--gold); color:black;" onclick="openReview('${p.name.replace(/'/g, "\\\\'")}', '${selectedCountry}')">${t.aiBtn}</button>
309
+ <button class="btn-action" style="background:#333; color:white;" onclick="window.open('${getMapUrl(p, selectedCountry)}', '_blank')">${t.mapBtn}</button>
310
  </div>`;
311
  list.appendChild(card);
312
  });
 
401
  box.appendChild(div); box.scrollTop = box.scrollHeight;
402
  }
403
 
 
404
  function markVisited(name) {
405
  let vp = JSON.parse(localStorage.getItem('visitedPlaces') || '[]');
406
  if(!vp.includes(name)) {
 
408
  localStorage.setItem('visitedPlaces', JSON.stringify(vp));
409
  visitedPlaces = vp;
410
  alert("✈️ Stamped on Passport!");
411
+ renderList();
412
  } else { alert("You already visited here!"); }
413
  }
414
 
415
+ // [핵심] 여권 정렬: 1. 방문한 곳(최신순) -> 2. 안 방문한 곳(나머지)
416
  function openPassport() {
417
  document.getElementById('passport-page').style.transform = 'translateX(0%)';
418
  visitedPlaces = JSON.parse(localStorage.getItem('visitedPlaces') || '[]');
 
419
  const grid = document.getElementById('stamp-grid');
420
  grid.innerHTML = "";
421
 
422
+ // 1. 방문한 곳 먼저 (거꾸로 = 최신순)
423
+ const reversedVp = [...visitedPlaces].reverse();
424
+ reversedVp.forEach(name => {
425
+ const div = document.createElement('div');
426
+ div.className = 'stamp active';
427
+ div.innerHTML = `🍷<br><b>${name}</b>`;
428
+ grid.appendChild(div);
429
+ });
430
+
431
+ // 2. 나머지 안 가본 곳
432
  for(let c in PLACE_DB) {
433
  PLACE_DB[c].forEach(p => {
434
+ if(!visitedPlaces.includes(p.name)) {
435
+ const div = document.createElement('div');
436
+ div.className = 'stamp';
437
+ div.innerHTML = `✈️`;
438
+ grid.appendChild(div);
439
+ }
440
  });
441
  }
442
  }
 
452
  const lbl = p.label || p.category || "";
453
  const desc = p['desc_'+currentLang.toLowerCase()] || p.desc_ko || "";
454
  const shortDesc = desc.length > 50 ? desc.substring(0, 50) + "..." : desc;
 
455
  const popupContent = `
456
  <div style="text-align:left;">
457
  <b style="color:#d4af37; font-size:14px;">${p.name}</b><br>
 
474
  function searchMap() {
475
  const q = document.getElementById('map-input').value.toLowerCase();
476
  if(!q) return;
 
477
  let found = false;
478
  for(let c in PLACE_DB) {
479
+ if(c.toLowerCase().includes(q)) { if(PLACE_DB[c].length>0 && PLACE_DB[c][0].lat) { worldMap.setView([PLACE_DB[c][0].lat, PLACE_DB[c][0].lon], 12); found=true; break; } }
 
 
 
 
 
480
  for(let p of PLACE_DB[c]) {
481
  const content = (p.name + " " + (p.address||"") + " " + (p.desc_ko||"")).toLowerCase();
482
+ if(content.includes(q)) { if(p.lat && p.lon) { worldMap.setView([p.lat, p.lon], 16); L.popup().setLatLng([p.lat, p.lon]).setContent(`<b>${p.name}</b>`).openOn(worldMap); found=true; break; } }
 
 
 
 
 
 
483
  }
484
  if(found) break;
485
  }