From 57d47ab25bf826927d82944a33894511c3b2df69 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 4 May 2025 18:32:59 +0800 Subject: [PATCH] fix related path error --- get_min_data.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/get_min_data.py b/get_min_data.py index 2a00767..46c1b4d 100644 --- a/get_min_data.py +++ b/get_min_data.py @@ -1,21 +1,46 @@ -from Ashare import * +from Ashare import * +from trade_day import * import os import time import csv +date = time.strftime("%Y-%m-%d", time.localtime()) +date = "2025-04-30" +save_path = os.path.split(os.path.realpath(__file__))[0] +save_path = os.path.join(save_path, date) +# 是否已经获取了数据 +file_count = 0 +if os.path.exists(save_path): + for root, dirs, files in os.walk(save_path): + file_count += len(files) +if file_count > 5000: + print("already pulled taday's data!") + exit() +# 今天是否是交易日 +ok, trade_day = is_trade_day(date) +if not ok or not trade_day: + print("taday is not trade day, skip") + exit() + +# 获取数据 stock_codes = {} -with open('table-r.txt', 'r', encoding='utf-8') as file: +stock_list_file = os.path.join(os.path.split(os.path.realpath(__file__))[0], 'table-r.txt') +with open(stock_list_file, 'r', encoding='utf-8') as file: csv_reader = csv.DictReader(file) for row in csv_reader: code = row["code"] if code.startswith("sh") or code.startswith("sz"): stock_codes[code] = row["name"] +if not os.path.exists(save_path): + os.makedirs(save_path) + for c, n in stock_codes.items(): print(f"getting stock:{c} name:{n}") file_name = str(c) + "-" + str(n) + ".txt" file_name = file_name.replace("*", "#") + file_name = os.path.join(save_path, file_name) if os.path.exists(file_name): print(f"file:{file_name} already exist, skip") continue