Skip to content

Commit

Permalink
add multi table portfolio
Browse files Browse the repository at this point in the history
  • Loading branch information
azuki774 committed Jun 16, 2024
1 parent 5fb9606 commit 5ece833
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/sbi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ def createCSV(table_data):


# ディレクトリ作成とファイル名取得する
def get_file_path():
def get_file_path(index):
today = datetime.date.today() # 出力:datetime.date(2020, 3, 22)
yyyymm = "{0:%Y%m}".format(today) # 202003
yyyymmdd = "{0:%Y%m%d}".format(today) # 20200322
os.makedirs(SAVE_DIR + yyyymm, exist_ok=True)

filepath = SAVE_DIR + yyyymm + "/" + yyyymmdd + ".csv"
filepath = SAVE_DIR + yyyymm + "/" + yyyymmdd + "_" + str(index) + ".csv"
return filepath


# 作成した文字列データ(CSV)を指定場所に書き込み
def writeCSV(rawoutputCSV):
filepath = get_file_path()
def writeCSV(rawoutputCSV, index):
filepath = get_file_path(index)
outputCSV = reshapeCSV(rawoutputCSV)

with open(filepath, mode="w") as f:
Expand Down Expand Up @@ -103,16 +103,17 @@ def reshapeCSV(rawoutputCSV):

soup = BeautifulSoup(driver.page_source, "html.parser")

# ポートフォリオの1テーブル目を取得
table_data = soup.find(
# ポートフォリオのテーブルを取得
table_data = soup.find_all(
"table", bgcolor="#9fbf99", cellpadding="4", cellspacing="1", width="100%"
)

fetch_data = createCSV(table_data)
lg.info("create CSV")

writeCSV(fetch_data)
lg.info("write CSV")
# 取得したテーブルを上から順に、#1, #2 をつけて YYYYMMDD_#x.csv として保存
for i in range(len(table_data)):
fetch_data = createCSV(table_data[i])
lg.info("create CSV: #{}".format(i + 1))
writeCSV(fetch_data, i + 1)
lg.info("write CSV")

# ブラウザを閉じる
driver.quit()

0 comments on commit 5ece833

Please sign in to comment.