diff --git a/StockCrawler.py b/StockCrawler.py index 26b6272..26d1261 100644 --- a/StockCrawler.py +++ b/StockCrawler.py @@ -1,11 +1,14 @@ import os import sys import time +import shutil from datetime import datetime +from dateutil.relativedelta import relativedelta + from stock.crawler.FnGuideCrawler import FnGuideCrawler from stock.crawler.MetaCrawler import MetaCrawler from stock.crawler.StockCrawler import StockCrawler - +from AnalyzerSqlite import AnalyzerSqlite class StockCrawlerDaily: @@ -15,6 +18,37 @@ class StockCrawlerDaily: return + def findCandidates(sefl, PROJECT_HOME): + RESOURCE_PATH = os.path.join(PROJECT_HOME, 'resources') + stockFileName = os.path.join(RESOURCE_PATH, 'stock.db') + analyzer = AnalyzerSqlite(stockFileName) + + analyzer.analyzeDaily() + analyzer.analyzeGrouping("weekly") + analyzer.analyzeGrouping("monthly") + + # 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") + before_7_day = datetime.today() + relativedelta(days=-7) + dayList = os.listdir(outPath) + for dayDir in dayList: + if dayDir[0] != '.' and dayDir < before_7_day.strftime("%Y%m%d"): + if os.path.exists(os.path.join(outPath, dayDir)) and os.path.isdir(os.path.join(outPath, dayDir)): + shutil.rmtree(os.path.join(outPath, dayDir)) + + outPath = os.path.join(outPath, day) + + if os.path.isdir(outPath): + shutil.rmtree(outPath) + os.mkdir(outPath) + print("print to Html...") + analyzer.findCandidates(outPath) + + return + def crawl(self): START_DATE = "2000.01.01" @@ -126,6 +160,10 @@ if __name__ == "__main__": if week in (0, 1, 2, 3, 4): # 0:월, 1:화, 2:수, 3:목, 4:금, 5:토, 6:일 start = time.time() stockCrawlerDaily.crawl() + + print("\n[후보 결정]") + stockCrawlerDaily.findCandidates(PROJECT_HOME) + today = datetime.now().strftime("%Y-%m-%d") print("time : %6.2f 초", (time.time() - start)) print("done...")