85 lines
2.7 KiB
Python
85 lines
2.7 KiB
Python
import os
|
|
import shutil
|
|
import time
|
|
from datetime import datetime
|
|
|
|
from stock.crawler.FnGuideCrawler import FnGuideCrawler
|
|
from stock.crawler.MetaCrawler import MetaCrawler
|
|
from stock.crawler.StockCrawler import StockCrawler
|
|
from stock.analysis.AnalyzerSqlite import AnalyzerSqlite
|
|
from stock.analysis.DailyStatus import DailyStatus
|
|
|
|
today = datetime.now().strftime("%Y-%m-%d")
|
|
|
|
# DB Browser for SQLite: http://hleecaster.com/python-sqlite3/
|
|
|
|
PROJECT_HOME = os.getcwd()
|
|
|
|
START_DATE = "2000.01.01"
|
|
start = time.time()
|
|
RESOURCE_PATH = os.path.join(PROJECT_HOME, 'resources')
|
|
stockFileName = os.path.join(RESOURCE_PATH, 'stock.db')
|
|
|
|
week = datetime.today().weekday()
|
|
|
|
if week in (0, 1, 2, 3, 4): # 0:월, 1:화, 2:수, 3:목, 4:금, 5:토, 6:일
|
|
# 재무제표는 3개월마다 다운로드를 한다.
|
|
fnGuideCrawler = FnGuideCrawler(START_DATE)
|
|
print("[KOSPI 상장기업 재무제표 다운로드]")
|
|
fnGuideCrawler.crawl_fnguide(stockFileName)
|
|
|
|
|
|
metaCrawler = MetaCrawler(START_DATE)
|
|
print("\n[증시자금동향 (신용잔고, 펀드자금 잔고)]")
|
|
metaCrawler.crawl_money_trend(stockFileName)
|
|
|
|
print("\n[국내 시장금리]")
|
|
metaCrawler.crawl_interest_rates(stockFileName)
|
|
|
|
print("\n[투자자별 매매동향(Trading_Trend)]")
|
|
metaCrawler.crawl_trading_trend(stockFileName)
|
|
|
|
print("\n[환율 (USD, JPY, EUR, CNY)]")
|
|
metaCrawler.crawl_exchange(stockFileName)
|
|
|
|
print("\n[원유 (WTI), 국제금, COPPER, NATURALGAS, CORN, SOYBEAN]")
|
|
metaCrawler.crawl_meterials(stockFileName)
|
|
|
|
|
|
|
|
print("\n[종목 다운로드]")
|
|
stockCrawler = StockCrawler(START_DATE)
|
|
stockCrawler.crawl_etf_stocks(stockFileName)
|
|
stockCrawler.crawl_stocks(stockFileName)
|
|
#stockCrawler.crawl_special_stocks(stockFileName)
|
|
|
|
print("\n[종목 분석]")
|
|
# S: 분석까지 진행
|
|
inFileName = PROJECT_HOME + '/resources/stock.db'
|
|
analyzerSqlite = AnalyzerSqlite(stockFileName)
|
|
|
|
analyzerSqlite.analyzeDaily()
|
|
analyzerSqlite.analyzeGrouping("weekly")
|
|
analyzerSqlite.analyzeGrouping("monthly")
|
|
|
|
print("\n[종목 결정]")
|
|
# HTML 출력
|
|
outPath = os.path.join(PROJECT_HOME, "resources", "analysis")
|
|
if not os.path.isdir(outPath):
|
|
os.mkdir(outPath)
|
|
day = datetime.today().strftime("%Y%m%d")
|
|
outPath = os.path.join(outPath, day)
|
|
if os.path.isdir(outPath):
|
|
shutil.rmtree(outPath)
|
|
os.mkdir(outPath)
|
|
|
|
analyzerSqlite.findCandidate(outPath)
|
|
|
|
# envelopes를 이용한 daily check
|
|
dailyStatus = DailyStatus(RESOURCE_PATH)
|
|
dailyStatus.checkEnvelope()
|
|
|
|
|
|
print("time : %6.2f 초", (time.time() - start))
|
|
print ("done...")
|