This commit is contained in:
dsyoon
2023-04-27 23:15:03 +09:00
parent d922398d26
commit 2104236d8f

View File

@@ -32,80 +32,170 @@ week = datetime.today().weekday()
slackBot = SlackBot() slackBot = SlackBot()
error_count = 0
if week in (0, 1, 2, 3, 4): # 0:월, 1:화, 2:수, 3:목, 4:금, 5:토, 6:일 if week in (0, 1, 2, 3, 4): # 0:월, 1:화, 2:수, 3:목, 4:금, 5:토, 6:일
slackBot.sendMsg("1. start to crawl...") slackBot.sendMsg("1. start to crawl...")
# 재무제표는 3개월마다 다운로드를 한다. ERROR_COUNT = 0
fnGuideCrawler = FnGuideCrawler(START_DATE) while ERROR_COUNT < 3:
print("[KOSPI 상장기업 재무제표 다운로드]") try:
fnGuideCrawler.crawl_fnguide(stockFileName) # 재무제표는 3개월마다 다운로드를 한다.
fnGuideCrawler = FnGuideCrawler(START_DATE)
print("[KOSPI 상장기업 재무제표 다운로드]")
fnGuideCrawler.crawl_fnguide(stockFileName)
break
except:
ERROR_COUNT += 1
continue
if ERROR_COUNT >= 3:
exit()
metaCrawler = MetaCrawler(START_DATE) metaCrawler = MetaCrawler(START_DATE)
print("\n[증시자금동향 (신용잔고, 펀드자금 잔고)]") ERROR_COUNT = 0
metaCrawler.crawl_money_trend(stockFileName) while ERROR_COUNT < 3:
slackBot.sendMsg("2. done meta data...") try:
print("\n[증시자금동향 (신용잔고, 펀드자금 잔고)]")
metaCrawler.crawl_money_trend(stockFileName)
slackBot.sendMsg("2. done meta data...")
break
except:
ERROR_COUNT += 1
continue
if ERROR_COUNT >= 3:
exit()
print("\n[국내 시장금리]") ERROR_COUNT = 0
metaCrawler.crawl_interest_rates(stockFileName) while ERROR_COUNT < 3:
slackBot.sendMsg("3. done interest rates...") try:
print("\n[국내 시장금리]")
metaCrawler.crawl_interest_rates(stockFileName)
slackBot.sendMsg("3. done interest rates...")
break
except:
ERROR_COUNT += 1
continue
if ERROR_COUNT >= 3:
exit()
print("\n[투자자별 매매동향(Trading_Trend)]") ERROR_COUNT = 0
metaCrawler.crawl_trading_trend(stockFileName) while ERROR_COUNT < 3:
slackBot.sendMsg("4. done trade trend...") try:
print("\n[투자자별 매매동향(Trading_Trend)]")
metaCrawler.crawl_trading_trend(stockFileName)
slackBot.sendMsg("4. done trade trend...")
break
except:
ERROR_COUNT += 1
continue
if ERROR_COUNT >= 3:
exit()
print("\n[환율 (USD, JPY, EUR, CNY)]") ERROR_COUNT = 0
metaCrawler.crawl_exchange(stockFileName) while ERROR_COUNT < 3:
slackBot.sendMsg("5. done exchange data...") try:
print("\n[환율 (USD, JPY, EUR, CNY)]")
metaCrawler.crawl_exchange(stockFileName)
slackBot.sendMsg("5. done exchange data...")
except:
ERROR_COUNT += 1
continue
if ERROR_COUNT >= 3:
exit()
print("\n[원유 (WTI), 국제금, COPPER, NATURALGAS, CORN, SOYBEAN]") ERROR_COUNT = 0
metaCrawler.crawl_meterials(stockFileName) while ERROR_COUNT < 3:
slackBot.sendMsg("6. done additional data...") try:
print("\n[원유 (WTI), 국제금, COPPER, NATURALGAS, CORN, SOYBEAN]")
metaCrawler.crawl_meterials(stockFileName)
slackBot.sendMsg("6. done additional data...")
except:
ERROR_COUNT += 1
continue
if ERROR_COUNT >= 3:
exit()
print("\n[종목 다운로드]") print("\n[종목 다운로드]")
stockCrawler = StockCrawler(START_DATE) stockCrawler = StockCrawler(START_DATE)
stockCrawler.crawl_etf_stocks(stockFileName) ERROR_COUNT = 0
slackBot.sendMsg("7. done etf stocks...") while ERROR_COUNT < 3:
stockCrawler.crawl_stocks(stockFileName) try:
slackBot.sendMsg("8. done stocks...") stockCrawler.crawl_etf_stocks(stockFileName)
stockCrawler.crawl_special_stocks(stockFileName) slackBot.sendMsg("7. done etf stocks...")
slackBot.sendMsg("9. done US stocks...") except:
ERROR_COUNT += 1
continue
if ERROR_COUNT >= 3:
exit()
ERROR_COUNT = 0
while ERROR_COUNT < 3:
try:
stockCrawler.crawl_stocks(stockFileName)
slackBot.sendMsg("8. done stocks...")
except:
ERROR_COUNT += 1
continue
if ERROR_COUNT >= 3:
exit()
ERROR_COUNT = 0
while ERROR_COUNT < 3:
try:
stockCrawler.crawl_special_stocks(stockFileName)
slackBot.sendMsg("9. done US stocks...")
except:
ERROR_COUNT += 1
continue
if ERROR_COUNT >= 3:
exit()
print("\n[종목 분석]")
# S: 분석까지 진행
inFileName = PROJECT_HOME + '/resources/stock.db' inFileName = PROJECT_HOME + '/resources/stock.db'
analyzerSqlite = AnalyzerSqlite(stockFileName) analyzerSqlite = AnalyzerSqlite(stockFileName)
#stockStatus = StockStatus(RESOURCE_PATH)
analyzerSqlite.analyzeDaily() ERROR_COUNT = 0
analyzerSqlite.analyzeGrouping("weekly") while ERROR_COUNT < 3:
analyzerSqlite.analyzeGrouping("monthly") try:
print("\n[종목 분석]")
# S: 분석까지 진행
analyzerSqlite.analyzeDaily()
analyzerSqlite.analyzeGrouping("weekly")
analyzerSqlite.analyzeGrouping("monthly")
slackBot.sendMsg("10. analyze...")
except:
ERROR_COUNT += 1
continue
if ERROR_COUNT >= 3:
exit()
print("\n[종목 결정]") ERROR_COUNT = 0
# HTML 출력 while ERROR_COUNT < 3:
outPath = os.path.join(PROJECT_HOME, "resources", "analysis") try:
if not os.path.isdir(outPath): print("\n[종목 결정]")
os.mkdir(outPath) # HTML 출력
day = datetime.today().strftime("%Y%m%d") outPath = os.path.join(PROJECT_HOME, "resources", "analysis")
before_7_day = datetime.today() + relativedelta(days=-7) if not os.path.isdir(outPath):
dayList = os.listdir(outPath) os.mkdir(outPath)
for dayDir in dayList: day = datetime.today().strftime("%Y%m%d")
if dayDir[0] != '.' and dayDir < before_7_day.strftime("%Y%m%d"): before_7_day = datetime.today() + relativedelta(days=-7)
if os.path.exists(os.path.join(outPath, dayDir)): dayList = os.listdir(outPath)
shutil.rmtree(os.path.join(outPath, dayDir)) for dayDir in dayList:
outPath = os.path.join(outPath, day) if dayDir[0] != '.' and dayDir < before_7_day.strftime("%Y%m%d"):
if os.path.isdir(outPath): if os.path.exists(os.path.join(outPath, dayDir)):
shutil.rmtree(outPath) shutil.rmtree(os.path.join(outPath, dayDir))
os.mkdir(outPath) outPath = os.path.join(outPath, day)
if os.path.isdir(outPath):
shutil.rmtree(outPath)
os.mkdir(outPath)
analyzerSqlite.findCandidates(outPath) analyzerSqlite.findCandidates(outPath)
#stockStatus.findCandidates(outPath) slackBot.sendMsg("11. done decision...")
except:
slackBot.sendMsg("10. done decision...") ERROR_COUNT += 1
continue
if ERROR_COUNT >= 3:
exit()
print("time : %6.2f", (time.time() - start)) print("time : %6.2f", (time.time() - start))