benjamin5607 commited on
Commit
7a319d1
Β·
verified Β·
1 Parent(s): 49f12e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -15
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,8 +58,12 @@ 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
  for col in df.select_dtypes(include=['object']).columns:
62
- df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True).str.replace('"', '\\"').str.replace("'", "\\'")
 
63
  if 'Country' in df.columns:
64
  df['Country'] = df['Country'].astype(str).str.strip()
65
  for country, group in df.groupby('Country'):
@@ -81,7 +85,7 @@ db_json_str = json.dumps(PLACE_DB, ensure_ascii=False)
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>
@@ -140,8 +144,6 @@ html_template = """
140
  .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; }
141
  .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; }
142
  .leaflet-popup-content-wrapper { background: #1a1a1a; color: white; border: 1px solid var(--gold); }
143
- .leaflet-popup-content { margin: 10px; }
144
-
145
  .stamp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; padding: 20px; }
146
  .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; }
147
  .stamp.active { border: 2px solid var(--gold); color: var(--gold); background: rgba(212,175,55,0.05); }
@@ -295,7 +297,7 @@ html_template = """
295
  <div class="pc-desc">${desc}</div>
296
  <div style="display:flex; gap:10px; margin-top:15px;">
297
  <button class="btn-action" style="background:var(--gold); color:black;" onclick="openReview('${p.name.replace(/'/g, "\\\\'")}', '${selectedCountry}')">${t.aiBtn}</button>
298
- <button class="btn-action" style="background:#333; color:white;" onclick="markVisited('${p.name}'); window.open('${getMapUrl(p, selectedCountry)}', '_blank')">${t.mapBtn}</button>
299
  </div>`;
300
  list.appendChild(card);
301
  });
@@ -390,20 +392,20 @@ html_template = """
390
  box.appendChild(div); box.scrollTop = box.scrollHeight;
391
  }
392
 
 
393
  function markVisited(name) {
394
- // [패치] μŠ€νƒ¬ν”„ 동기화 둜직 κ°•ν™” (μ΅œμ‹ κ°’ λ‹€μ‹œ λ‘œλ“œ)
395
  let vp = JSON.parse(localStorage.getItem('visitedPlaces') || '[]');
396
  if(!vp.includes(name)) {
397
  vp.push(name);
398
  localStorage.setItem('visitedPlaces', JSON.stringify(vp));
399
- visitedPlaces = vp; // λ©”λͺ¨λ¦¬ λ³€μˆ˜ μ¦‰μ‹œ 동기화
400
  alert("✈️ Stamped on Passport!");
401
  } else { alert("You already visited here!"); }
402
  }
403
 
 
404
  function openPassport() {
405
  document.getElementById('passport-page').style.transform = 'translateX(0%)';
406
- // [패치] μ—¬κΆŒ μ—΄ λ•Œλ§ˆλ‹€ λ‘œμ»¬μŠ€ν† λ¦¬μ§€μ—μ„œ μ΅œμ‹  데이터 κ°•μ œ λ‘œλ“œ
407
  visitedPlaces = JSON.parse(localStorage.getItem('visitedPlaces') || '[]');
408
 
409
  const grid = document.getElementById('stamp-grid');
@@ -419,7 +421,6 @@ html_template = """
419
  });
420
  }
421
  }
422
-
423
  function closePassport() { document.getElementById('passport-page').style.transform = 'translateX(-100%)'; }
424
 
425
  function openMap() {
@@ -452,24 +453,19 @@ html_template = """
452
 
453
  function closeMap() { document.getElementById('world-map-page').style.transform = 'translateY(100%)'; }
454
 
455
- // [패치] 검색 κΈ°λŠ₯ κ°•ν™”: 이름, μ£Όμ†Œ, μ„€λͺ…, λ„μ‹œμ΄λ¦„(ν‚€κ°’) λͺ¨λ‘ 검색
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
- // 1. λ‚˜λΌ/λ„μ‹œ 이름 체크
463
  if(c.toLowerCase().includes(q)) {
464
- // ν•΄λ‹Ή λ„μ‹œμ˜ 첫 번째 μž₯μ†Œλ‘œ 이동
465
  if(PLACE_DB[c].length > 0 && PLACE_DB[c][0].lat && PLACE_DB[c][0].lon) {
466
  worldMap.setView([PLACE_DB[c][0].lat, PLACE_DB[c][0].lon], 12);
467
  found = true; break;
468
  }
469
  }
470
- // 2. μž₯μ†Œ 상세 체크
471
  for(let p of PLACE_DB[c]) {
472
- // 이름 + μ£Όμ†Œ + μ„€λͺ…을 λͺ¨λ‘ ν•©μ³μ„œ 검색
473
  const content = (p.name + " " + (p.address||"") + " " + (p.desc_ko||"")).toLowerCase();
474
  if(content.includes(q)) {
475
  if(p.lat && p.lon) {
 
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
+
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
  db_base64 = base64.b64encode(db_json_str.encode('utf-8')).decode('utf-8')
86
 
87
  # ==========================================
88
+ # πŸ–₯️ 3. 톡합 ν”„λ‘ νŠΈμ—”λ“œ (μŠ€νƒ¬ν”„ 둜직 정상화)
89
  # ==========================================
90
  html_template = """
91
  <!DOCTYPE html>
 
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); }
 
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
  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)) {
399
  vp.push(name);
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');
 
421
  });
422
  }
423
  }
 
424
  function closePassport() { document.getElementById('passport-page').style.transform = 'translateX(-100%)'; }
425
 
426
  function openMap() {
 
453
 
454
  function closeMap() { document.getElementById('world-map-page').style.transform = 'translateY(100%)'; }
455
 
 
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) {