Compare commits

..

2 Commits

Author SHA1 Message Date
ac87063d24 chore: prices 날짜 범위 자동화
Some checks failed
Docker Build and Deploy / build-and-push (push) Failing after 1m6s
Docker Build and Deploy / deploy (push) Has been skipped
2025-04-09 22:23:04 +09:00
26e77a23fb chore: 장 마감일 파싱 수정 2025-04-09 22:19:06 +09:00
4 changed files with 30 additions and 8 deletions

View File

@ -3,6 +3,7 @@ attrs==25.3.0
bcrypt==4.3.0 bcrypt==4.3.0
beautifulsoup4==4.13.3 beautifulsoup4==4.13.3
blinker==1.9.0 blinker==1.9.0
bt==1.1.0
cachetools==5.5.2 cachetools==5.5.2
captcha==0.7.1 captcha==0.7.1
certifi==2025.1.31 certifi==2025.1.31
@ -30,6 +31,7 @@ joblib==1.4.2
jsonschema==4.23.0 jsonschema==4.23.0
jsonschema-specifications==2024.10.1 jsonschema-specifications==2024.10.1
keyring==25.6.0 keyring==25.6.0
keyrings.alt==5.0.2
kiwisolver==1.4.8 kiwisolver==1.4.8
lxml==5.3.1 lxml==5.3.1
MarkupSafe==3.0.2 MarkupSafe==3.0.2

View File

@ -26,6 +26,15 @@ def get_latest_biz_day():
return biz_day return biz_day
def get_latest_biz_day2():
url = 'https://finance.naver.com/sise/sise_index.naver?code=KOSPI'
data = rq.post(url)
data_html = BeautifulSoup(data.content, 'lxml')
parse_day = data_html.select_one('div.group_heading > div.ly_realtime > span#time').text
biz_day = re.findall('[0-9]+', parse_day)
biz_day = ''.join(biz_day)
return biz_day
# 업종 분류 현황 가져옴 # 업종 분류 현황 가져옴
def get_stock_data(biz_day, mkt_id): def get_stock_data(biz_day, mkt_id):
# logging.basicConfig(level=logging.DEBUG) # logging.basicConfig(level=logging.DEBUG)
@ -188,6 +197,7 @@ def save_sector(sector):
if __name__ == '__main__': if __name__ == '__main__':
# sector와 ticker 갱신 # sector와 ticker 갱신
latest_biz_day = get_latest_biz_day() latest_biz_day = get_latest_biz_day2()
# latest_biz_day='20250331'
process_for_total_stock(latest_biz_day) process_for_total_stock(latest_biz_day)
process_for_wics(latest_biz_day) process_for_wics(latest_biz_day)

View File

@ -1,5 +1,5 @@
import time import time
from datetime import date from datetime import date, datetime, timedelta
from io import BytesIO from io import BytesIO
import pandas as pd import pandas as pd
@ -36,11 +36,21 @@ def process_for_price():
# 티커 선택 # 티커 선택
ticker = ticker_list['종목코드'][i] ticker = ticker_list['종목코드'][i]
# todo: 날짜 범위 수정 # 시작일(최근 저장 날짜 다음날)과 종료일(오늘)
# 시작일과 종료일 to = date.today().strftime("%Y%m%d")
# fr = (date.today() + relativedelta(years=-5)).strftime("%Y%m%d")
to = (date.today()).strftime("%Y%m%d") # 최근 날짜 조회
fr = '20250301' latest_date_query = "SELECT MAX(날짜) AS latest_date FROM kor_price WHERE 종목코드 = %s"
mycursor.execute(latest_date_query, (ticker,))
result = mycursor.fetchone()
if result[0] is not None:
# 최근 날짜가 있으면 그 다음날부터 조회
latest_date = result[0]
fr = (latest_date + timedelta(days=1)).strftime("%Y%m%d")
else:
# 데이터가 없으면 기본값 사용 (필요에 따라 조정)
fr = '20250328'
# 오류 발생 시 이를 무시하고 다음 루프로 진행 # 오류 발생 시 이를 무시하고 다음 루프로 진행
try: try:

View File

@ -16,7 +16,7 @@ def render_data_page():
with st.spinner('주식 데이터 수집중...'): with st.spinner('주식 데이터 수집중...'):
try: try:
# Call the krx data collection function # Call the krx data collection function
biz_day = krx.get_latest_biz_day() biz_day = krx.get_latest_biz_day2()
krx.process_for_total_stock(biz_day) krx.process_for_total_stock(biz_day)
krx.process_for_wics(biz_day) krx.process_for_wics(biz_day)
# Show success message # Show success message