# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import tensorflow as tf
# !pip install h5py --upgrade

# !pip install tensorflow

# !pip install konlpy

# !java --version

from selenium import webdriver
import schedule
import time
from datetime import datetime, timedelta
import sqlite3
from bs4 import BeautifulSoup
import tensorflow as tf
import konlpy
import pickle
from konlpy.tag import Okt

driver = webdriver.Chrome('./chromedriver.exe')

driver.get('https://finance.naver.com/news/market_special.nhn')

elem = driver.find_element_by_xpath('//*[@id="contentarea_left"]/div[2]/table/tbody/tr[1]/td[1]/a')
elem.click()

html = driver.page_source
html

soup = BeautifulSoup(html, 'html.parser')
soup

presses = soup.select('span.press > img')
press = presses[0]['title']
press

datas = soup.select('div.article_info > h3')
title2 = datas[0].text.strip()
title1 = title2.replace("'","")
title = title1.replace('"','')
title

dates = soup.select('div.article_sponsor > span')
date = dates[0].text.strip()
date

contents = soup.select('div#content')
content1 = contents[0]
for tag in content1.find_all(['li', 'h3']):
    tag.replace_with('')
    content = content1.text.strip()
content

import requests

req = requests.get('https://finance.naver.com/news/market_special.nhn?&page=1')
req

soup1 = BeautifulSoup(req.text, 'html.parser')
soup1

hrefs = soup1.select('td.publicSubject > a')
href1 = hrefs[0]
href1

href = 'https://finance.naver.com'+ href1['href']
href

times = soup1.select('td.wdate')
times

time1 = times[0]
time1

time = time1.text.strip()[-5:]
time

loaded_model = tf.keras.models.load_model('./naver_finance_news_deeplearnig.h5')
stopwords = pickle.load(open('./stopwords.pkl','rb'))
tokenizer = pickle.load(open('./tokenizer.pkl','rb'))

stopwords = pickle.load(open('./stopwords.pkl','rb'))
print(stopwords)

tokenizer = pickle.load(open('./tokenizer.pkl','rb'))
tokenizer

loaded_model = tf.keras.models.load_model('./naver_finance_news_deeplearnig.h5')
loaded_model

title = '크래프톤 5% 급등…장중 공모가 회복(종합)'

okt = konlpy.tag.Okt()

new_sentence = okt.morphs(title, stem=True)

new_sentence = [ tok for tok in new_sentence if tok not in stopwords ]

encoded = tokenizer.texts_to_sequences([new_sentence])

pad_new = tf.keras.preprocessing.sequence.pad_sequences(encoded, maxlen=50)

score = loaded_model.predict(pad_new)

if(score > 0.5):
  posi_nega = 1
else:
  posi_nega = 0

posi_nega



StarcoderdataJupyterScriptsDedupFiltered