파이썬 네이버 상한가 찾기 GUI [심화]
import pandas as pd
import requests
import sys
import datetime
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class MyWindow(QMainWindow):
def __init__(self):
super().__init__()
# Main Window
self.setGeometry(0, 0, 1145, 1024)
self.setWindowTitle("KOSPI & KOSDAQ 오늘의 상한가 종목")
# KOSPI 버튼
btn_kospi = QPushButton("KOSPI", self)
btn_kospi.move(10, 10)
btn_kospi.clicked.connect(self.btn_kospi_clicked)
# KOSPI 테이블
self.tableWidget_kospi = QTableWidget(self)
self.tableWidget_kospi.move(10, 50)
self.tableWidget_kospi.resize(1125, 300)
self.tableWidget_kospi.setColumnCount(11)
kospi = ['종목명', '현재가', '전일비', '등락률', '거래량', '시가', '고가', '저가', 'PER', '연속', '누적']
self.tableWidget_kospi.setHorizontalHeaderLabels(kospi)
# KOSDAQ 버튼
btn_kosdaq = QPushButton("KOSDAQ", self)
btn_kosdaq.move(10, 380)
btn_kosdaq.clicked.connect(self.btn_kosdaq_clicked)
# KOSDAQ 테이블
self.tableWidget_kosdaq = QTableWidget(self)
self.tableWidget_kosdaq.move(10, 420)
self.tableWidget_kosdaq.resize(1125, 580)
self.tableWidget_kosdaq.setColumnCount(11)
kosdaq = ['종목명', '현재가', '전일비', '등락률', '거래량', '시가', '고가', '저가', 'PER', '연속', '누적']
self.tableWidget_kosdaq.setHorizontalHeaderLabels(kosdaq)
def btn_kospi_clicked(self):
html = requests.get('https://finance.naver.com/sise/sise_upper.nhn')
if html != 200:
sys.exit
table = pd.read_html(html.text)
kospi = table[1]
kospi = kospi[['종목명', '현재가', '전일비', '등락률', '거래량', '시가', '고가', '저가', 'PER', '연속', '누적']].dropna(thresh=3)
#print("코스피 상한가 목록")
if kospi.size <= 110:
kospi_row = int(kospi.size%10)
else :
kospi_row = int(kospi.size/10-1)
self.tableWidget_kospi.setRowCount(kospi_row)
if kospi.size == 0:
print("없습니다.")
else:
print(kospi.size%10)
result_name = 'KOSPI_result' + datetime.datetime.today().strftime("%y%m%d") + '.xlsx'
kospi.to_excel(result_name, sheet_name='Sheet1')
for i in range(kospi_row):
for j in range(11):
self.tableWidget_kospi.setItem(i, j, QTableWidgetItem(str(kospi.iat[i, j])))
def btn_kosdaq_clicked(self):
html = requests.get('https://finance.naver.com/sise/sise_upper.nhn')
if html != 200:
sys.exit
table = pd.read_html(html.text)
kosdaq = table[2]
print(kosdaq)
kosdaq = kosdaq[['종목명', '현재가', '전일비', '등락률', '거래량', '시가', '고가', '저가', 'PER', '연속', '누적']].dropna(thresh=3)
print(kosdaq)
#print("코스닥 상한가 목록")
if kosdaq.size <= 110:
kosdaq_row = int(kosdaq.size%10)
else :
kosdaq_row = int(kosdaq.size/10-1)
self.tableWidget_kosdaq.setRowCount(kosdaq_row)
if kosdaq.size == 0:
print("없습니다.")
else:
print(kosdaq.size)
result_name = 'KOSDAQ_result' + datetime.datetime.today().strftime("%y%m%d") + '.xlsx'
kosdaq.to_excel(result_name, sheet_name='Sheet1')
for i in range(kosdaq_row):
for j in range(11):
self.tableWidget_kosdaq.setItem(i, j, QTableWidgetItem(str(kosdaq.iat[i, j])))
app = QApplication(sys.argv)
window = MyWindow()
window.show()
app.exec_()
'Programming > Python' 카테고리의 다른 글
파이썬 Modbus TCP Poll [GUI] (0) | 2021.06.14 |
---|---|
파이썬 py pyw 차이 (0) | 2021.06.03 |
티스토리 api access_token 받아오기 (0) | 2021.05.07 |
파이썬 네이버 상한가 찾기 (0) | 2021.05.07 |
파이썬 네이버 블로그 자동으로 글 쓰기 (0) | 2021.05.07 |