chore: common class 추가, db 접속 시 common 사용하도록 개선
This commit is contained in:
parent
aa5807690b
commit
97e2f8190c
@ -1,29 +1,14 @@
|
||||
# 패키지 불러오기
|
||||
import os
|
||||
from urllib.parse import quote_plus
|
||||
|
||||
import pymysql
|
||||
from sqlalchemy import create_engine
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
from dotenv import load_dotenv
|
||||
import pandas as pd
|
||||
|
||||
load_dotenv()
|
||||
user = os.getenv('DB_USER')
|
||||
pw = os.getenv('DB_PW')
|
||||
engine_for_pw = quote_plus(pw)
|
||||
host = os.getenv('DB_HOST')
|
||||
port = int(os.getenv('DB_PORT'))
|
||||
db = os.getenv('DB_DB')
|
||||
import quantcommon
|
||||
|
||||
# DB 연결
|
||||
engine = create_engine(f'mysql+pymysql://{user}:{engine_for_pw}@{host}:{port}/{db}')
|
||||
con = pymysql.connect(user=user,
|
||||
passwd=pw,
|
||||
host=host,
|
||||
port=port,
|
||||
db=db,
|
||||
charset='utf8')
|
||||
common = quantcommon.QuantCommon()
|
||||
engine = common.create_engine()
|
||||
con = common.connect()
|
||||
|
||||
mycursor = con.cursor()
|
||||
# 가치 지표 계산
|
||||
# 분기 재무제표 불러오기
|
||||
|
||||
@ -1,32 +1,18 @@
|
||||
import os
|
||||
from urllib.parse import quote_plus
|
||||
import re
|
||||
import time
|
||||
|
||||
import pymysql
|
||||
from sqlalchemy import create_engine
|
||||
import pandas as pd
|
||||
import requests as rq
|
||||
from bs4 import BeautifulSoup
|
||||
import re
|
||||
from tqdm import tqdm
|
||||
import time
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
user = os.getenv('DB_USER')
|
||||
pw = os.getenv('DB_PW')
|
||||
engine_for_pw = quote_plus(pw)
|
||||
host = os.getenv('DB_HOST')
|
||||
port = int(os.getenv('DB_PORT'))
|
||||
db = os.getenv('DB_DB')
|
||||
import quantcommon
|
||||
|
||||
# DB 연결
|
||||
engine = create_engine(f'mysql+pymysql://{user}:{engine_for_pw}@{host}:{port}/{db}')
|
||||
con = pymysql.connect(user=user,
|
||||
passwd=pw,
|
||||
host=host,
|
||||
port=port,
|
||||
db=db,
|
||||
charset='utf8')
|
||||
common = quantcommon.QuantCommon()
|
||||
engine = common.create_engine()
|
||||
con = common.connect()
|
||||
|
||||
mycursor = con.cursor()
|
||||
|
||||
# 제무재표 크롤링
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
from io import BytesIO
|
||||
@ -9,8 +7,8 @@ import pandas as pd
|
||||
import requests as rq
|
||||
from tqdm import tqdm
|
||||
from bs4 import BeautifulSoup
|
||||
import pymysql
|
||||
from dotenv import load_dotenv
|
||||
import quantcommon
|
||||
|
||||
load_dotenv()
|
||||
|
||||
@ -125,12 +123,7 @@ def process_for_total_stock(biz_day):
|
||||
|
||||
|
||||
def save_ticker(ticker):
|
||||
con = pymysql.connect(user=os.getenv('DB_USER'),
|
||||
passwd=os.getenv('DB_PW'),
|
||||
host=os.getenv('DB_HOST'),
|
||||
port=int(os.getenv('DB_PORT')),
|
||||
db=os.getenv('DB_DB'),
|
||||
charset='utf8')
|
||||
con = quantcommon.QuantCommon().connect()
|
||||
|
||||
mycursor = con.cursor()
|
||||
query = f"""
|
||||
@ -175,12 +168,7 @@ def process_for_wics(biz_day):
|
||||
|
||||
|
||||
def save_sector(sector):
|
||||
con = pymysql.connect(user=os.getenv('DB_USER'),
|
||||
passwd=os.getenv('DB_PW'),
|
||||
host=os.getenv('DB_HOST'),
|
||||
port=int(os.getenv('DB_PORT')),
|
||||
db=os.getenv('DB_DB'),
|
||||
charset='utf8')
|
||||
con = quantcommon.QuantCommon().connect()
|
||||
|
||||
mycursor = con.cursor()
|
||||
query = f"""
|
||||
@ -201,4 +189,4 @@ def save_sector(sector):
|
||||
if __name__ == '__main__':
|
||||
latest_biz_day = get_latest_biz_day()
|
||||
process_for_total_stock(latest_biz_day)
|
||||
# process_for_wics(latest_biz_day)
|
||||
process_for_wics(latest_biz_day)
|
||||
|
||||
@ -1,34 +1,21 @@
|
||||
# 패키지 불러오기
|
||||
import os
|
||||
from urllib.parse import quote_plus
|
||||
|
||||
import pymysql
|
||||
from sqlalchemy import create_engine
|
||||
import pandas as pd
|
||||
from datetime import date
|
||||
from dateutil.relativedelta import relativedelta
|
||||
import requests as rq
|
||||
import time
|
||||
from tqdm import tqdm
|
||||
from datetime import date
|
||||
from io import BytesIO
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
user = os.getenv('DB_USER')
|
||||
pw = os.getenv('DB_PW')
|
||||
engine_for_pw = quote_plus(pw)
|
||||
host = os.getenv('DB_HOST')
|
||||
port = int(os.getenv('DB_PORT'))
|
||||
db = os.getenv('DB_DB')
|
||||
import pandas as pd
|
||||
import requests as rq
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from tqdm import tqdm
|
||||
|
||||
import quantcommon
|
||||
|
||||
# DB 연결
|
||||
engine = create_engine(f'mysql+pymysql://{user}:{engine_for_pw}@{host}:{port}/{db}')
|
||||
con = pymysql.connect(user=user,
|
||||
passwd=pw,
|
||||
host=host,
|
||||
port=port,
|
||||
db=db,
|
||||
charset='utf8')
|
||||
common = quantcommon.QuantCommon()
|
||||
engine = common.create_engine()
|
||||
con = common.connect()
|
||||
|
||||
mycursor = con.cursor()
|
||||
|
||||
# 티커리스트 불러오기
|
||||
|
||||
28
example/quantcommon.py
Normal file
28
example/quantcommon.py
Normal file
@ -0,0 +1,28 @@
|
||||
import os
|
||||
from urllib.parse import quote_plus
|
||||
|
||||
import pymysql
|
||||
from dotenv import load_dotenv
|
||||
from sqlalchemy import create_engine
|
||||
|
||||
|
||||
class QuantCommon:
|
||||
def __init__(self):
|
||||
load_dotenv()
|
||||
self.user = os.getenv('DB_USER')
|
||||
self.pw = os.getenv('DB_PW')
|
||||
self.engine_for_pw = quote_plus(self.pw)
|
||||
self.host = os.getenv('DB_HOST')
|
||||
self.port = int(os.getenv('DB_PORT'))
|
||||
self.db = os.getenv('DB_DB')
|
||||
|
||||
def create_engine(self):
|
||||
return create_engine(f'mysql+pymysql://{self.user}:{self.engine_for_pw}@{self.host}:{self.port}/{self.db}')
|
||||
|
||||
def connect(self):
|
||||
return pymysql.connect(user=self.user,
|
||||
passwd=self.pw,
|
||||
host=self.host,
|
||||
port=self.port,
|
||||
db=self.db,
|
||||
charset='utf8')
|
||||
Loading…
x
Reference in New Issue
Block a user