daily_crawler.py 1.58 KB
import math
import pymysql
import datetime
from sqlalchemy import create_engine
import pandas as pd
from PyQt5.QtCore import *

import cf

pymysql.install_as_MySQLdb()

# -* daily_crawler *-
# 종목별 일자별 데이터를 저장하는 데이터베이스

class daily_crawler():
    def __init__(self, db_name, daily_craw_db_name, daily_buy_list_db_name):
        # db_name==0인 경우는 simulator
        if db_name != 0:
            self.db_name = db_name
            self.daily_craw_db_name = daily_craw_db_name

            self.daily_buy_list_db_name = daily_buy_list_db_name

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

            self.variable_setting()
        else:
            pass

    # 업데이트가 금일 제대로 끝났는지 확인하는 함수
    def variable_setting(self):

        self.market_start_time = QTime(9, 0, 0)         # 장 시작시간
        self.market_end_time = QTime(15, 31, 0)         # 장 마감시간

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

    # 현재 시간에 장이 열려있는지 확인하는 함수
    def market_time_check(self):
        self.current_time = QTime.currentTime()
        if self.current_time > self.market_start_time and self.current_time < self.market_end_time:
            return True
        else:
            return False