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
|
| 6 |
+
import hmac
|
| 7 |
+
import hashlib
|
| 8 |
+
import base64
|
| 9 |
+
from datetime import datetime, timedelta
|
| 10 |
+
import random
|
| 11 |
+
import re
|
| 12 |
+
|
| 13 |
+
# [์ง๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ]
|
| 14 |
+
import folium
|
| 15 |
+
from streamlit_folium import st_folium
|
| 16 |
+
|
| 17 |
+
# ==========================================
|
| 18 |
+
# 0. API ํค ๋ฐ ์ค์
|
| 19 |
+
# ==========================================
|
| 20 |
+
|
| 21 |
+
# [1] ์นด์นด์ค API (ํ์)
|
| 22 |
+
KAKAO_REST_KEY = "968344aed4aff4d7aeb37eb199767d5a"
|
| 23 |
+
|
| 24 |
+
# [2] ๋ค์ด๋ฒ ๊ด๊ณ API
|
| 25 |
+
AD_API_KEY = "01000000002855c92d066a6e30d3eaeafbe6adebd688d73c3dd901f151b52c430ddcad5c88"
|
| 26 |
+
AD_SECRET_KEY = "AQAAAAAoVcktBmpuMNPq6vvmrevWXrbXSbEoh/+/3U3vTcTLyA=="
|
| 27 |
+
AD_CUSTOMER_ID = "4173931"
|
| 28 |
+
|
| 29 |
+
# [3] ๊ธฐํ ์ค์
|
| 30 |
+
NAVER_SEARCH_ID = "dlOt9fIfGfpSj69uICWc"
|
| 31 |
+
NAVER_SEARCH_SECRET = "_rtIqpqYpd"
|
| 32 |
+
YOUTUBE_API_KEY = "AIzaSyBPgiYOvrPJ4cacWQ42UQb_KZobCcpOIH0"
|
| 33 |
+
|
| 34 |
+
EXCLUDED_KEYWORDS = ["์๋งํฌ", "์จ๋ง์ง", "์ธ์๋ผ", "์ธ๋ชจ๋", "ํฐํ๋"]
|
| 35 |
+
|
| 36 |
+
# ==========================================
|
| 37 |
+
# 1. ํต์ฌ ๊ธฐ๋ฅ ํจ์
|
| 38 |
+
# ==========================================
|
| 39 |
+
|
| 40 |
+
def search_places_kakao(query):
|
| 41 |
+
"""์ฅ์ ๊ฒ์"""
|
| 42 |
+
url = "https://dapi.kakao.com/v2/local/search/keyword.json"
|
| 43 |
+
headers = {"Authorization": f"KakaoAK {KAKAO_REST_KEY}"}
|
| 44 |
+
try:
|
| 45 |
+
res = requests.get(url, params={"query": query, "size": 15}, headers=headers)
|
| 46 |
+
return res.json()['documents'] if res.status_code == 200 else []
|
| 47 |
+
except: return []
|
| 48 |
+
|
| 49 |
+
def get_address_details_kakao(address_str):
|
| 50 |
+
"""์ฃผ์ -> ์ขํ + ๋ฒ์ ๋ ๋ถ์"""
|
| 51 |
+
url = "https://dapi.kakao.com/v2/local/search/address.json"
|
| 52 |
+
headers = {"Authorization": f"KakaoAK {KAKAO_REST_KEY}"}
|
| 53 |
+
try:
|
| 54 |
+
res = requests.get(url, params={"query": address_str}, headers=headers)
|
| 55 |
+
if res.status_code == 200:
|
| 56 |
+
docs = res.json()['documents']
|
| 57 |
+
if docs:
|
| 58 |
+
data = docs[0]
|
| 59 |
+
x, y = float(data['x']), float(data['y'])
|
| 60 |
+
addr = data.get('address', {})
|
| 61 |
+
|
| 62 |
+
region_1 = addr.get('region_1depth_name', '') # ์ถฉ๋ถ
|
| 63 |
+
region_2 = addr.get('region_2depth_name', '') # ์ฒญ์ฃผ์ ์๋น๊ตฌ
|
| 64 |
+
|
| 65 |
+
city_name = ""
|
| 66 |
+
gu_name = ""
|
| 67 |
+
if region_2:
|
| 68 |
+
parts = region_2.split()
|
| 69 |
+
if len(parts) >= 2:
|
| 70 |
+
city_name = parts[0] # ์ฒญ์ฃผ์
|
| 71 |
+
gu_name = parts[1] # ์๋น๊ตฌ
|
| 72 |
+
else:
|
| 73 |
+
gu_name = parts[0] # ๊ฐ๋จ๊ตฌ
|
| 74 |
+
|
| 75 |
+
b_dong = addr.get('region_3depth_name', '') # ๋ฒ์ ๋
|
| 76 |
+
return x, y, region_1, city_name, gu_name, b_dong
|
| 77 |
+
return 0.0, 0.0, "", "", "", ""
|
| 78 |
+
except: return 0.0, 0.0, "", "", "", ""
|
| 79 |
+
|
| 80 |
+
def get_admin_dong(x, y):
|
| 81 |
+
"""ํ์ ๋ ์ถ์ถ (์ค์๋ ๋ฑ)"""
|
| 82 |
+
if x == 0.0 or y == 0.0: return ""
|
| 83 |
+
url = "https://dapi.kakao.com/v2/local/geo/coord2regioncode.json"
|
| 84 |
+
headers = {"Authorization": f"KakaoAK {KAKAO_REST_KEY}"}
|
| 85 |
+
try:
|
| 86 |
+
res = requests.get(url, params={"x": x, "y": y}, headers=headers)
|
| 87 |
+
if res.status_code == 200:
|
| 88 |
+
docs = res.json()['documents']
|
| 89 |
+
for doc in docs:
|
| 90 |
+
if doc['region_type'] == 'H': return doc['region_3depth_name']
|
| 91 |
+
return ""
|
| 92 |
+
except: return ""
|
| 93 |
+
|
| 94 |
+
def get_nearby_stations(x, y):
|
| 95 |
+
if x == 0.0 or y == 0.0: return []
|
| 96 |
+
url = "https://dapi.kakao.com/v2/local/search/category.json"
|
| 97 |
+
headers = {"Authorization": f"KakaoAK {KAKAO_REST_KEY}"}
|
| 98 |
+
params = {"category_group_code": "SW8", "x": x, "y": y, "radius": 1500, "sort": "distance"}
|
| 99 |
+
try:
|
| 100 |
+
res = requests.get(url, params=params, headers=headers)
|
| 101 |
+
if res.status_code == 200:
|
| 102 |
+
return [{"name": d['place_name'], "clean_name": d['place_name'].split()[0].replace("์ญ",""), "x": float(d['x']), "y": float(d['y'])} for d in res.json()['documents']][:4]
|
| 103 |
+
return []
|
| 104 |
+
except: return []
|
| 105 |
+
|
| 106 |
+
def get_naver_expanded_rankings(seed_keywords, category_seed, filters, loc_info):
|
| 107 |
+
"""
|
| 108 |
+
[ํต์ฌ] ์์น ๊ธฐ๋ฐ ํํฐ๋ง (ํ์ดํธ๋ฆฌ์คํธ ๋ฐฉ์)
|
| 109 |
+
"""
|
| 110 |
+
uri = '/keywordstool'
|
| 111 |
+
timestamp = str(int(time.time() * 1000))
|
| 112 |
+
msg = f"{timestamp}.GET.{uri}"
|
| 113 |
+
signature = base64.b64encode(hmac.new(bytes(AD_SECRET_KEY, 'UTF-8'), bytes(msg, 'UTF-8'), hashlib.sha256).digest())
|
| 114 |
+
headers = {'X-Timestamp': timestamp, 'X-API-KEY': AD_API_KEY, 'X-Customer': AD_CUSTOMER_ID, 'X-Signature': signature}
|
| 115 |
+
|
| 116 |
+
clean_seeds = []
|
| 117 |
+
seen = set()
|
| 118 |
+
for k in seed_keywords:
|
| 119 |
+
k_nospace = k.replace(" ", "")
|
| 120 |
+
if k_nospace not in seen:
|
| 121 |
+
clean_seeds.append(k_nospace)
|
| 122 |
+
seen.add(k_nospace)
|
| 123 |
+
|
| 124 |
+
# [ํ์ดํธ๋ฆฌ์คํธ] ํ์ ๊ตฌ์ญ ๋ฐ ์ญ ์ด๋ฆ ์ ์
|
| 125 |
+
valid_local_terms = []
|
| 126 |
+
if loc_info['si']: valid_local_terms.append(loc_info['si'].replace("์", ""))
|
| 127 |
+
if loc_info['gu']: valid_local_terms.append(loc_info['gu'])
|
| 128 |
+
if loc_info['b_dong']: valid_local_terms.append(re.sub(r'\d+๊ฐ?', '', loc_info['b_dong']))
|
| 129 |
+
if loc_info['h_dong']: valid_local_terms.append(loc_info['h_dong'])
|
| 130 |
+
for s in loc_info['stations']: valid_local_terms.append(s['clean_name'])
|
| 131 |
+
valid_local_terms = list(set(valid_local_terms))
|
| 132 |
+
|
| 133 |
+
all_results = []
|
| 134 |
+
seen_kwd = set()
|
| 135 |
+
|
| 136 |
+
for i in range(0, len(clean_seeds), 5):
|
| 137 |
+
chunk = clean_seeds[i:i+5]
|
| 138 |
+
try:
|
| 139 |
+
res = requests.get("https://api.naver.com" + uri, params={'hintKeywords': ','.join(chunk), 'showDetail': '1'}, headers=headers)
|
| 140 |
+
if res.status_code == 200:
|
| 141 |
+
data = res.json()
|
| 142 |
+
for item in data.get('keywordList', []):
|
| 143 |
+
kwd = item['relKeyword'].replace(" ", "")
|
| 144 |
+
if kwd in seen_kwd: continue
|
| 145 |
+
if category_seed not in kwd: continue
|
| 146 |
+
if kwd == category_seed: continue
|
| 147 |
+
if any(bad in kwd for bad in EXCLUDED_KEYWORDS): continue
|
| 148 |
+
|
| 149 |
+
is_local_relevant = False
|
| 150 |
+
for term in valid_local_terms:
|
| 151 |
+
if term in kwd:
|
| 152 |
+
is_local_relevant = True
|
| 153 |
+
break
|
| 154 |
+
if not is_local_relevant: continue
|
| 155 |
+
|
| 156 |
+
if not filters['station']:
|
| 157 |
+
if "์ญ" in kwd: continue
|
| 158 |
+
is_station_word = False
|
| 159 |
+
for s in loc_info['stations']:
|
| 160 |
+
if s['clean_name'] in kwd: is_station_word = True; break
|
| 161 |
+
if is_station_word: continue
|
| 162 |
+
|
| 163 |
+
priority = 0
|
| 164 |
+
if kwd in clean_seeds: priority = 100
|
| 165 |
+
for main_k in loc_info['main_keywords']:
|
| 166 |
+
if main_k in kwd: priority += 20
|
| 167 |
+
|
| 168 |
+
seen_kwd.add(kwd)
|
| 169 |
+
pc = item['monthlyPcQcCnt']
|
| 170 |
+
mo = item['monthlyMobileQcCnt']
|
| 171 |
+
if isinstance(pc, str): pc = 10
|
| 172 |
+
if isinstance(mo, str): mo = 10
|
| 173 |
+
all_results.append({'key': item['relKeyword'], 'total': pc + mo, 'priority': priority})
|
| 174 |
+
time.sleep(0.1)
|
| 175 |
+
except: pass
|
| 176 |
+
return sorted(all_results, key=lambda x: (x['priority'], x['total']), reverse=True)
|
| 177 |
+
|
| 178 |
+
def search_bloggers(keyword, display=30):
|
| 179 |
+
url = "https://openapi.naver.com/v1/search/blog.json"
|
| 180 |
+
headers = {"X-Naver-Client-Id": NAVER_SEARCH_ID, "X-Naver-Client-Secret": NAVER_SEARCH_SECRET}
|
| 181 |
+
params = {"query": keyword, "display": display, "sort": "sim"}
|
| 182 |
+
try:
|
| 183 |
+
res = requests.get(url, params=params, headers=headers)
|
| 184 |
+
if res.status_code == 200: return res.json()['items']
|
| 185 |
+
return None
|
| 186 |
+
except: return None
|
| 187 |
+
|
| 188 |
+
# ==========================================
|
| 189 |
+
# 2. ๋ฉ์ธ UI
|
| 190 |
+
# ==========================================
|
| 191 |
+
st.set_page_config(page_title="๋ณ์ ๋ง์ผํ
๋ง์คํฐ", layout="wide")
|
| 192 |
+
|
| 193 |
+
st.markdown("""
|
| 194 |
+
<style>
|
| 195 |
+
#myBtn { display: flex; justify-content: center; align-items: center; position: fixed; bottom: 30px; right: 30px; z-index: 9999;
|
| 196 |
+
font-size: 20px; border: none; outline: none; background-color: #E1306C; color: white; cursor: pointer; width: 50px; height: 50px;
|
| 197 |
+
padding: 0; border-radius: 50%; box-shadow: 0px 4px 6px rgba(0,0,0,0.2); transition: transform 0.2s; }
|
| 198 |
+
#myBtn:hover { transform: scale(1.1); }
|
| 199 |
+
</style>
|
| 200 |
+
<button onclick="window.parent.document.querySelector('.main').scrollTo({top:0, behavior:'smooth'})" id="myBtn">โฒ</button>
|
| 201 |
+
""", unsafe_allow_html=True)
|
| 202 |
+
|
| 203 |
+
if 'target_location' not in st.session_state: st.session_state.target_location = None
|
| 204 |
+
if 'analysis_result' not in st.session_state: st.session_state.analysis_result = pd.DataFrame()
|
| 205 |
+
if 'search_results' not in st.session_state: st.session_state.search_results = []
|
| 206 |
+
|
| 207 |
+
st.title("๐ฅ ๋ณ์ ๋ง์ผํ
์ฌ์ธ์ ํด")
|
| 208 |
+
tab1, tab2, tab3, tab4 = st.tabs(["๐ ํค์๋ ๋ถ์ (Map)", "๐ ๋ธ๋ก๊ฑฐ ๋ฐ๊ตด", "๐บ ์ ํ๋ฒ ๋ฐ๊ตด", "๐ธ ์ธ์คํ ๋ฐ๊ตด"])
|
| 209 |
+
|
| 210 |
+
with tab1:
|
| 211 |
+
st.header("1. ์ง๋ ๊ธฐ๋ฐ ์๊ถ ๋ถ์ ๋ฐ ํค์๋ ์ถ์ถ")
|
| 212 |
+
with st.expander("๐ ๋ณ์ ๊ฒ์ ๋ฐ ์์น ์ค์ ", expanded=True):
|
| 213 |
+
with st.form("search_form"):
|
| 214 |
+
col1, col2 = st.columns([3, 1], vertical_alignment="bottom")
|
| 215 |
+
with col1: h_query = st.text_input("๋ณ์๋ช
์
๋ ฅ", placeholder="์: ๋์ํธ์์ ์ฒญ์ฃผ")
|
| 216 |
+
with col2: search_btn = st.form_submit_button("๋ณ์ ์ฐพ๊ธฐ")
|
| 217 |
+
if search_btn and h_query:
|
| 218 |
+
places = search_places_kakao(h_query)
|
| 219 |
+
if places: st.session_state.search_results = places
|
| 220 |
+
else: st.warning("๊ฒ์ ๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค.")
|
| 221 |
+
if st.session_state.search_results:
|
| 222 |
+
st.divider()
|
| 223 |
+
options = {f"{p['place_name']} ({p['address_name']})": i for i, p in enumerate(st.session_state.search_results)}
|
| 224 |
+
selected_option = st.radio("๋ถ์ํ ๋ณ์์ ์ ํํ์ธ์", list(options.keys()))
|
| 225 |
+
if st.button("โ
์ ํํ ๋ณ์์ผ๋ก ์ค์ "):
|
| 226 |
+
target = st.session_state.search_results[options[selected_option]]
|
| 227 |
+
x, y, region_1, city, gu, b_dong = get_address_details_kakao(target['address_name'])
|
| 228 |
+
st.session_state.target_location = {"name": target['place_name'], "x": x, "y": y, "do": region_1, "si": city, "gu": gu, "b_dong": b_dong, "h_dong": get_admin_dong(x, y)}
|
| 229 |
+
st.session_state.target_location['stations'] = get_nearby_stations(x, y)
|
| 230 |
+
st.rerun()
|
| 231 |
+
|
| 232 |
+
if st.session_state.target_location:
|
| 233 |
+
loc = st.session_state.target_location
|
| 234 |
+
col1, col2 = st.columns([1.2, 1])
|
| 235 |
+
with col2:
|
| 236 |
+
st.subheader("๐บ๏ธ ๋ถ์ ๊ตฌ์ญ")
|
| 237 |
+
# [์์ ] ํ
์คํธ ๋งํ์ (DivIcon) ๊ธฐ๋ฅ์ด ์ ๊ฑฐ๋ ๊นจ๋ํ ์ง๋
|
| 238 |
+
m = folium.Map(location=[loc['y'], loc['x']], zoom_start=15)
|
| 239 |
+
folium.Marker([loc['y'], loc['x']], popup=f"<b>{loc['name']}</b>", tooltip=loc['name'], icon=folium.Icon(color="red", icon="star", prefix='fa')).add_to(m)
|
| 240 |
+
folium.Circle(location=[loc['y'], loc['x']], radius=1500, color='#E1306C', fill=True, fill_color='#E1306C', fill_opacity=0.1).add_to(m)
|
| 241 |
+
for s in loc['stations']:
|
| 242 |
+
folium.Marker([s['y'], s['x']], tooltip=f"{s['name']} (์ญ์ธ๊ถ)", popup=s['name'], icon=folium.Icon(color="green", icon="train", prefix="fa")).add_to(m)
|
| 243 |
+
st_folium(m, height=450, width="100%")
|
| 244 |
+
|
| 245 |
+
# [AI ์๊ถ ๋ถ์ ๋ฆฌํฌํธ]
|
| 246 |
+
st_names = [s['name'] for s in loc['stations']]
|
| 247 |
+
st_text = ", ".join(st_names) if st_names else "๋๋ณด๊ถ ๋ด ์งํ์ฒ ์ญ ์์"
|
| 248 |
+
dong_name = loc['h_dong'] if loc['h_dong'] else loc['b_dong']
|
| 249 |
+
|
| 250 |
+
report_box = f"""
|
| 251 |
+
<div style="background-color:#f0f2f6; padding:15px; border-radius:10px; border-left: 5px solid #E1306C;">
|
| 252 |
+
<h4 style="margin:0 0 10px 0;">๐ข AI ๋ง์ผํ
์๊ถ ๋ถ์</h4>
|
| 253 |
+
<ul style="margin:0; padding-left:20px;">
|
| 254 |
+
<li><b>๐ ํ์ ๊ตฌ์ญ:</b> ํ์ฌ <b>{loc['si']} {loc['gu']} {dong_name}</b> ์ง์ญ์ ๋ถ์ ์ค์
๋๋ค.</li>
|
| 255 |
+
<li><b>๐ ๊ตํต/์ ๊ทผ์ฑ:</b> ์ด ๋ณ์์ <b>{st_text}</b> ์ธ๊ทผ์ ์์นํด ์์ต๋๋ค.</li>
|
| 256 |
+
<li><b>๐ก ์ ๋ต:</b> ์ง์ญ๋ช
(<b>{loc['gu']}, {dong_name}</b>)์ด ํฌํจ๋ ํค์๋๋ฅผ ์ต์ฐ์ ์ผ๋ก ์ ์ ํ์ธ์.</li>
|
| 257 |
+
</ul>
|
| 258 |
+
</div>
|
| 259 |
+
"""
|
| 260 |
+
st.markdown(report_box, unsafe_allow_html=True)
|
| 261 |
+
|
| 262 |
+
with col1:
|
| 263 |
+
disp_addr = f"{loc['si']} {loc['gu']} {loc['b_dong']}"
|
| 264 |
+
if loc['h_dong'] and loc['h_dong'] != loc['b_dong']: disp_addr += f" ({loc['h_dong']})"
|
| 265 |
+
st.subheader(f"๐ {disp_addr}")
|
| 266 |
+
st.write("๐ฏ **ํค์๋ ์ถ์ถ ์ต์
**")
|
| 267 |
+
c1, c2 = st.columns(2)
|
| 268 |
+
use_region = c1.checkbox("๐๏ธ ์ง์ญ๋ช
(์/๊ตฌ/๋)", True)
|
| 269 |
+
use_station = c2.checkbox("๐ ์ญ์ธ๊ถ", True)
|
| 270 |
+
target_cat = st.selectbox("์
์ข
", ["ํผ๋ถ๊ณผ", "์ฑํ์ธ๊ณผ", "์น๊ณผ", "ํ์์", "์ ํ์ธ๊ณผ", "์๊ณผ", "๋น๋จ๊ธฐ๊ณผ", "์ฐ๋ถ์ธ๊ณผ"])
|
| 271 |
+
|
| 272 |
+
if st.button("๐ ํค์๋ ์ถ์ถ", type="primary", use_container_width=True):
|
| 273 |
+
with st.spinner("์ง์ญ ๊ธฐ๋ฐ ์ ๋ฐ ๋ถ์ ์ค..."):
|
| 274 |
+
seeds = []
|
| 275 |
+
main_keywords = []
|
| 276 |
+
clean_si = loc['si'].replace("์", "") if loc['si'] else ""
|
| 277 |
+
if use_region:
|
| 278 |
+
if clean_si: seeds.extend([f"{clean_si}{target_cat}", f"{clean_si}{target_cat}์ถ์ฒ"])
|
| 279 |
+
if loc['gu']: seeds.extend([f"{loc['gu']}{target_cat}", f"{clean_si}{loc['gu']}{target_cat}"])
|
| 280 |
+
clean_b = re.sub(r'\d+๊ฐ?', '', loc['b_dong'])
|
| 281 |
+
seeds.append(f"{clean_b}{target_cat}")
|
| 282 |
+
if loc['h_dong']: seeds.append(f"{loc['h_dong']}{target_cat}")
|
| 283 |
+
if use_station:
|
| 284 |
+
for s in loc['stations']: seeds.extend([f"{s['clean_name']}์ญ{target_cat}", f"{s['clean_name']}{target_cat}"])
|
| 285 |
+
loc['main_keywords'] = [clean_si, loc['gu'], loc['h_dong']]
|
| 286 |
+
rankings = get_naver_expanded_rankings(seeds, target_cat, {'station': use_station}, loc)
|
| 287 |
+
if rankings: st.session_state.analysis_result = pd.DataFrame(rankings)
|
| 288 |
+
|
| 289 |
+
if not st.session_state.analysis_result.empty:
|
| 290 |
+
df = st.session_state.analysis_result
|
| 291 |
+
st.success(f"ํค์๋ {len(df)}๊ฐ")
|
| 292 |
+
for _, row in df.head(30).iterrows():
|
| 293 |
+
icon = "๐" if row['priority'] >= 100 else ("๐ฏ" if row['priority'] >= 60 else "โ
")
|
| 294 |
+
st.markdown(f"""<div style="border:1px solid #eee; padding:10px; margin-bottom:5px; border-radius:5px; display:flex; justify-content:space-between; align-items:center; background-color:{'#fff0f6' if row['priority']>=80 else 'white'};">
|
| 295 |
+
<div><b>{row['key']}</b> <span style="font-size:0.8em; color:#E1306C;">{icon}</span></div>
|
| 296 |
+
<div style="text-align:right;"><span style="font-size:0.8em; color:#666;">์กฐํ์</span><br><b>{row['total']:,}</b></div>
|
| 297 |
+
</div>""", unsafe_allow_html=True)
|
| 298 |
+
st.download_button("๐ฅ ๋ค์ด๋ก๋", df.to_csv(index=False).encode('utf-8-sig'), "keywords.csv", "text/csv", use_container_width=True)
|
| 299 |
+
|
| 300 |
+
with tab2:
|
| 301 |
+
st.header("2. ๋ธ๋ก๊ฑฐ ๋ฐ๊ตด")
|
| 302 |
+
with st.form("blog_form"):
|
| 303 |
+
col_b1, col_b2 = st.columns([3, 1], vertical_alignment="bottom")
|
| 304 |
+
with col_b1: region_input = st.text_input("ํ๊ฒ ์ง์ญ๋ช
", placeholder="์: ์ฒญ์ฃผ ์ฑ์๊ธธ")
|
| 305 |
+
with col_b2: submit_blog = st.form_submit_button("๐ต๏ธโโ๏ธ ๋ธ๋ก๊ฑฐ ์ฐพ๊ธฐ")
|
| 306 |
+
if submit_blog and region_input:
|
| 307 |
+
with st.spinner("๋ธ๋ก๊ฑฐ ๋ถ์ ์ค..."):
|
| 308 |
+
items = search_bloggers(f"{region_input} ํผ๋ถ๊ณผ ํ๊ธฐ", 30)
|
| 309 |
+
if items:
|
| 310 |
+
for i in items:
|
| 311 |
+
st.write(f"- [{i['bloggername']}] {i['title'].replace('<b>','').replace('</b>','')}")
|
| 312 |
+
st.caption(f"๐ {i['link']}")
|
| 313 |
+
|
| 314 |
+
with tab3:
|
| 315 |
+
st.header("3. ์ ํ๋ธ")
|
| 316 |
+
st.info("์ค๋น์ค")
|
| 317 |
+
|
| 318 |
+
with tab4:
|
| 319 |
+
st.header("4. ์ธ์คํ")
|
| 320 |
+
st.info("์ค๋น์ค")
|