Update app.py
Browse files
app.py
CHANGED
@@ -36,8 +36,10 @@ def crawl_chats(vod_url):
|
|
36 |
chat_logs = []
|
37 |
chat_counts = defaultdict(int)
|
38 |
laugh_counts = defaultdict(int)
|
|
|
39 |
|
40 |
# 채팅 데이터를 순차적으로 요청하여 가져오기
|
|
|
41 |
while True:
|
42 |
# API 요청 보내기
|
43 |
response = requests.get(url, params=params, headers=headers)
|
@@ -90,6 +92,9 @@ def crawl_chats(vod_url):
|
|
90 |
if len(re.findall(r'ㅋ', chat_content)) >= 4:
|
91 |
laugh_counts[minute_key] += 1
|
92 |
|
|
|
|
|
|
|
93 |
# 다음 요청을 위해 playerMessageTime 파라미터 업데이트
|
94 |
next_time = data["content"].get("nextPlayerMessageTime")
|
95 |
if next_time is None:
|
@@ -132,6 +137,19 @@ if st.button("크롤링 시작"):
|
|
132 |
|
133 |
# 이전에 크롤링한 결과가 있으면 그래프와 다운로드 버튼 표시
|
134 |
if st.session_state['chat_logs']:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
# 데이터프레임 생성
|
136 |
times = [time.strftime('%H:%M:%S') for time in st.session_state['chat_counts'].keys()]
|
137 |
chat_numbers = list(st.session_state['chat_counts'].values())
|
@@ -167,7 +185,7 @@ if st.session_state['chat_logs']:
|
|
167 |
xaxis_title="시간",
|
168 |
yaxis_title="채팅 개수",
|
169 |
xaxis=dict(
|
170 |
-
showticklabels=
|
171 |
),
|
172 |
hovermode="x unified", # 마우스를 올렸을 때 해당 x축에서 툴팁 표시
|
173 |
showlegend=True, # 범례 표시
|
@@ -175,4 +193,4 @@ if st.session_state['chat_logs']:
|
|
175 |
)
|
176 |
|
177 |
# 그래프 출력
|
178 |
-
st.plotly_chart(fig)
|
|
|
36 |
chat_logs = []
|
37 |
chat_counts = defaultdict(int)
|
38 |
laugh_counts = defaultdict(int)
|
39 |
+
total_chats_collected = 0 # 총 수집된 채팅 개수
|
40 |
|
41 |
# 채팅 데이터를 순차적으로 요청하여 가져오기
|
42 |
+
status_text = st.empty() # 상태 메시지 출력용
|
43 |
while True:
|
44 |
# API 요청 보내기
|
45 |
response = requests.get(url, params=params, headers=headers)
|
|
|
92 |
if len(re.findall(r'ㅋ', chat_content)) >= 4:
|
93 |
laugh_counts[minute_key] += 1
|
94 |
|
95 |
+
total_chats_collected += len(chats)
|
96 |
+
status_text.text(f"현재까지 수집된 채팅 메시지 개수: {total_chats_collected}")
|
97 |
+
|
98 |
# 다음 요청을 위해 playerMessageTime 파라미터 업데이트
|
99 |
next_time = data["content"].get("nextPlayerMessageTime")
|
100 |
if next_time is None:
|
|
|
137 |
|
138 |
# 이전에 크롤링한 결과가 있으면 그래프와 다운로드 버튼 표시
|
139 |
if st.session_state['chat_logs']:
|
140 |
+
# 좌우 여백을 줄이기 위한 CSS 추가 (그래프 부분만 적용)
|
141 |
+
st.markdown(
|
142 |
+
"""
|
143 |
+
<style>
|
144 |
+
.block-container {
|
145 |
+
padding-left: 10px;
|
146 |
+
padding-right: 10px;
|
147 |
+
}
|
148 |
+
</style>
|
149 |
+
""",
|
150 |
+
unsafe_allow_html=True
|
151 |
+
)
|
152 |
+
|
153 |
# 데이터프레임 생성
|
154 |
times = [time.strftime('%H:%M:%S') for time in st.session_state['chat_counts'].keys()]
|
155 |
chat_numbers = list(st.session_state['chat_counts'].values())
|
|
|
185 |
xaxis_title="시간",
|
186 |
yaxis_title="채팅 개수",
|
187 |
xaxis=dict(
|
188 |
+
showticklabels=False # x축 시간 레이블 숨김
|
189 |
),
|
190 |
hovermode="x unified", # 마우스를 올렸을 때 해당 x축에서 툴팁 표시
|
191 |
showlegend=True, # 범례 표시
|
|
|
193 |
)
|
194 |
|
195 |
# 그래프 출력
|
196 |
+
st.plotly_chart(fig, use_container_width=True) # 화면 너비에 맞게 출력
|