stock_info.py 2.18 KB
from sqlalchemy import *
from PyQt5.QtCore import *
import datetime
import pandas as pd

import config

class Stock_Info():
    def __init__(self,db_name,daily_db_name,stock_db_name):
        if db_name!=0:
            self.db_name=db_name
            self.daily_db_name=daily_db_name
            self.stock_db_name=stock_db_name

            self.engine=create_engine(
                "mysql+pymysql://" + config.db_id + ":" + config.db_pw + "@" + config.db_ip + ":" + config.db_port +
                "/stock_info", encoding='utf-8')
            self.conn=self.engine.connect()

            self.set_variable()

    # 변수 설정
    def set_variable(self):
        self.mkt_start_time=QTime(9,0,0)
        self.mkt_end_time=QTime(15,31,0)

        self.today=datetime.datetime.today().strftime("%Y%m%d")
        self.today_time=datetime.datetime.today().strftime("%Y%m%d%H%M")

    # 현재 시간이 주식 장이 열린 시간인지 확인하는 함수
    def check_time(self):
        self.current_time=QTime.currentTime()
        if self.current_time>self.mkt_start_time and self.current_time<self.mkt_end_time:
            return True
        else:
            return False

    # 코스피 주식 리스트 저장
    def get_item_kospi(self):
        self.kospi_list = pd.read_html(
            'http://kind.krx.co.kr/corpgeneral/corpList.do?method=download&searchType=13&marketType=stockMkt',
            header=0)[0]

        self.kospi_list.종목코드 = self.kospi_list.종목코드.map('{:06d}'.format)
        self.kospi_list = self.kospi_list[['회사명', '종목코드']]
        self.kospi_list = self.kospi_list.rename(columns={'회사명': 'code_name', '종목코드': 'code'})

    # 코스닥 주식 리스트 저장
    def get_item_kosdaq(self):
        self.kosdaq_list = pd.read_html(
            'http://kind.krx.co.kr/corpgeneral/corpList.do?method=download&searchType=13&marketType=kosdaqMkt',
            header=0)[0]

        self.kosdaq_list.종목코드 = self.kosdaq_list.종목코드.map('{:06d}'.format)
        self.kosdaq_list = self.kosdaq_list[['회사명', '종목코드']]
        self.kosdaq_list = self.kosdaq_list.rename(columns={'회사명': 'code_name', '종목코드': 'code'})