From 72828f3d393d47f3541a00746158b34071af7e1d Mon Sep 17 00:00:00 2001 From: dsyoon Date: Fri, 12 Nov 2021 23:02:51 +0900 Subject: [PATCH] =?UTF-8?q?=EC=8A=A4=ED=86=A0=EC=BA=90=EC=8A=A4=ED=8B=B1,?= =?UTF-8?q?=20RSI=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stockpredictor/analysis/Analyzer.py | 8 ++++---- .../crawler/toSQLite/StockCrawler.py | 20 ++++++++++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/stockpredictor/analysis/Analyzer.py b/stockpredictor/analysis/Analyzer.py index 63da66e..5aab8c4 100644 --- a/stockpredictor/analysis/Analyzer.py +++ b/stockpredictor/analysis/Analyzer.py @@ -377,13 +377,13 @@ class Analyzer: return status, buy_price - def getPositionalEnergy(self, stock, i): + def getPositionalEnergy(self, stock, last_index): # 260 (= 52 * 5)일 중 가장 찾은 금액과 가장 높았던 금액 중 현재가의 위치 계산 - top = stock[i]['close'] - bottom = stock[i]['close'] + top = stock[last_index]['close'] + bottom = stock[last_index]['close'] - for i in range(8, 260): + for i in range(1, 260): if i > len(stock) or not stock[-i]: break diff --git a/stockpredictor/crawler/toSQLite/StockCrawler.py b/stockpredictor/crawler/toSQLite/StockCrawler.py index fb4ceae..286808c 100644 --- a/stockpredictor/crawler/toSQLite/StockCrawler.py +++ b/stockpredictor/crawler/toSQLite/StockCrawler.py @@ -5,6 +5,7 @@ import re import json import sqlite3 import requests +import math class Queue(object): def __init__(self, max): @@ -144,7 +145,8 @@ class StockCrawler: stocks.append({"NAME": 'KODEX 은행', "CODE": "091170", "PRICE": []}) stocks.append({"NAME": 'TIGER 탄소효율그린뉴딜', "CODE": "376410", "PRICE": []}) - for stock in stocks: + for i, stock in enumerate(stocks): + print (i, stock["NAME"], stock["CODE"]) cursor.execute('SELECT * FROM ' + tableName + ' WHERE CODE=?', (stock["CODE"],)) result = cursor.fetchone() if result != None: @@ -213,6 +215,8 @@ class StockCrawler: lastDay = "" if len(stock) > 0 and len(stock["PRICE"]) - 1 > 0: lastDay = stock["PRICE"][len(stock["PRICE"]) - 1]["DATE"].replace("-", ".") + + date_set = set() lastPage = False # 1페이지에서 1000페이지의 데이터만 가져오기 for page in range(1, self.limit_page_count): @@ -220,14 +224,23 @@ class StockCrawler: pg_url = '{url}&page={page}'.format(url=url, page=page) #html = pd.read_html(pg_url, header=0) html = pd.read_html(requests.get(pg_url, headers=self.header).text) - count = 0 for date in html[0].날짜.values: if type(date) is str: - count += 1 + if date in date_set: + lastPage = True + break + date_set.add(date) + if date == lastDay: lastPage = True df = df.append(html[0], ignore_index=True) break + df = df.append(html[0], ignore_index=True) + if lastPage: + print("\t- lastpage:", page) + break + + """ if count == 10: df = df.append(html[0], ignore_index=True) if lastPage: @@ -238,6 +251,7 @@ class StockCrawler: lastPage = True else: break + """ # df.dropna()를 이용해 결측값 있는 행 제거 df = df.dropna()