fix related path error
This commit is contained in:
parent
f2b95a1859
commit
57d47ab25b
@ -1,21 +1,46 @@
|
|||||||
from Ashare import *
|
from Ashare import *
|
||||||
|
from trade_day import *
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import csv
|
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 = {}
|
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)
|
csv_reader = csv.DictReader(file)
|
||||||
for row in csv_reader:
|
for row in csv_reader:
|
||||||
code = row["code"]
|
code = row["code"]
|
||||||
if code.startswith("sh") or code.startswith("sz"):
|
if code.startswith("sh") or code.startswith("sz"):
|
||||||
stock_codes[code] = row["name"]
|
stock_codes[code] = row["name"]
|
||||||
|
|
||||||
|
if not os.path.exists(save_path):
|
||||||
|
os.makedirs(save_path)
|
||||||
|
|
||||||
for c, n in stock_codes.items():
|
for c, n in stock_codes.items():
|
||||||
print(f"getting stock:{c} name:{n}")
|
print(f"getting stock:{c} name:{n}")
|
||||||
file_name = str(c) + "-" + str(n) + ".txt"
|
file_name = str(c) + "-" + str(n) + ".txt"
|
||||||
file_name = file_name.replace("*", "#")
|
file_name = file_name.replace("*", "#")
|
||||||
|
file_name = os.path.join(save_path, file_name)
|
||||||
if os.path.exists(file_name):
|
if os.path.exists(file_name):
|
||||||
print(f"file:{file_name} already exist, skip")
|
print(f"file:{file_name} already exist, skip")
|
||||||
continue
|
continue
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user