Spaces:
Sleeping
Sleeping
Update app.py
Browse files8 unmodified lines9101112131443 unmodified lines58596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911023 unmodified lines1341351361371381391406 unmodified lines14714814915015115215311 unmodified lines16516616716816917017111 unmodified lines1831841851861871881898 unmodified linesimport requestsfrom bs4 import BeautifulSoupimport timePATH = './checkpoint-18750/'SEQ_LEN = 12843 unmodified linesreturn predict_answerdef get_comments(news_url):# oid, aid 추출list = news_url.split("/")oid = list[-2]aid = list[-1]if len(aid) > 10:aid = aid[:10]# API URL 구성api_url = "https://apis.naver.com/commentBox/cbox/web_naver_list_jsonp.json"params = {"ticket": "news","templateId": "default_society","pool": "cbox5","lang": "ko","country": "KR","objectId": f"news{oid},{aid}","pageSize": 100,"indexSize": 10,"page": 1,"sort": "FAVORITE" # 'NEW'(최신순), 'FAVORITE'(순공감순)}headers = {"User-Agent": "Mozilla/5.0","Referer": news_url}# API 호출 및 데이터 처리response = requests.get(api_url, params=params, headers=headers)content = response.text.replace("_callback(", "").replace(");", "")json_data = json.loads(content)response = requests.get(news_url)article_soup = BeautifulSoup(response.text, "html.parser")# 제목 추출title = article_soup.select_one("#ct > div.media_end_head.go_trans > div.media_end_head_title > h2")if title is None:title = article_soup.select_one("#content > div.end_ct > div > h2")# 본문 추출article = article_soup.select_one("#dic_area")if article is None:article = article_soup.select_one("#articeBody")return title.text.strip(), article.text.strip(), processing_data(json_data['result']['commentList'])def processing_data(comments):comment_list = []23 unmodified linestitle, content, comments = get_comments(url)# 결과 표시st.subheader("기사 제목")st.write(title)st.subheader("본문 내용")6 unmodified lines# 결과 표시st.subheader("기사 제목")st.write(title)st.subheader("본문 내용")11 unmodified linestitle, content, comments = get_comments(url)# 결과 표시st.subheader("기사 제목")st.write(title)st.subheader("본문 내용")11 unmodified linestitle, content, comments = get_comments(url)# 결과 표시st.subheader("기사 제목")st.write(title)st.subheader("본문 내용")8 unmodified lines91011121314151643 unmodified lines6061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012123 unmodified lines1451461471481491501516 unmodified lines15815916016116216316411 unmodified lines17617717817918018118211 unmodified lines1941951961971981992008 unmodified linesimport requestsfrom bs4 import BeautifulSoupimport timeimport instaloaderfrom instaloader import PostPATH = './checkpoint-18750/'SEQ_LEN = 12843 unmodified linesreturn predict_answerdef get_comments(news_url):if ('naver' in news_url):# oid, aid 추출list = news_url.split("/")oid = list[-2]aid = list[-1]if len(aid) > 10:aid = aid[:10]# API URL 구성api_url = "https://apis.naver.com/commentBox/cbox/web_naver_list_jsonp.json"params = {"ticket": "news","templateId": "default_society","pool": "cbox5","lang": "ko","country": "KR","objectId": f"news{oid},{aid}","pageSize": 100,"indexSize": 10,"page": 1,"sort": "FAVORITE" # 'NEW'(최신순), 'FAVORITE'(순공감순)}headers = {"User-Agent": "Mozilla/5.0","Referer": news_url}# API 호출 및 데이터 처리response = requests.get(api_url, params=params, headers=headers)content = response.text.replace("_callback(", "").replace(");", "")json_data = json.loads(content)response = requests.get(news_url)article_soup = BeautifulSoup(response.text, "html.parser")# 제목 추출title = article_soup.select_one("#ct > div.media_end_head.go_trans > div.media_end_head_title > h2")if title is None:title = article_soup.select_one("#content > div.end_ct > div > h2")# 본문 추출article = article_soup.select_one("#dic_area")if article is None:article = article_soup.select_one("#articeBody")return title.text.strip(), article.text.strip(), processing_data(json_data['result']['commentList'])else if ('insta' in news_url):list = news_url.split('/')pid = list[-2] + list[-1]L = instaloader.Instaloader()post = Post.from_shortcode(L.context, pid)return '', post.caption, post.commentsdef processing_data(comments):comment_list = []23 unmodified linestitle, content, comments = get_comments(url)# 결과 표시st.subheader("제목")st.write(title)st.subheader("본문 내용")6 unmodified lines# 결과 표시st.subheader("제목")st.write(title)st.subheader("본문 내용")11 unmodified linestitle, content, comments = get_comments(url)# 결과 표시st.subheader("제목")st.write(title)st.subheader("본문 내용")11 unmodified linestitle, content, comments = get_comments(url)# 결과 표시st.subheader("제목")st.write(title)st.subheader("본문 내용")
app.py+58-47