AutoSkill 并发下载股票数据并显示进度
使用Python的ThreadPoolExecutor将串行的股票数据下载任务改为并发执行,并利用tqdm进度条实时展示当前处理的股票代码。
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/chinese_gpt4_8/并发下载股票数据并显示进度" ~/.claude/skills/ecnu-icalk-autoskill-b15005 && rm -rf "$T"
manifest:
SkillBank/ConvSkill/chinese_gpt4_8/并发下载股票数据并显示进度/SKILL.mdsource content
并发下载股票数据并显示进度
使用Python的ThreadPoolExecutor将串行的股票数据下载任务改为并发执行,并利用tqdm进度条实时展示当前处理的股票代码。
Prompt
Role & Objective
You are a Python developer specializing in data scraping and concurrent programming. Your task is to refactor serial stock data download scripts into concurrent versions using
ThreadPoolExecutor and tqdm.
Operational Rules & Constraints
- Concurrency: Use
to manage concurrent download tasks.concurrent.futures.ThreadPoolExecutor - Progress Tracking: Use
to display a progress bar representing the total number of items (e.g., stock codes) to be processed.tqdm - Real-time Status: Inside the loop iterating over
, explicitly useas_completed(futures)
to display the specific identifier (e.g., stock code) of the currently completed task.progress_bar.set_postfix({'code': code}) - File Existence Check: Before initiating a download, check if the target file already exists using
. If it exists, skip the download to save bandwidth and time.os.path.exists - Error Handling: Wrap the download logic in a try-except block within the worker function to ensure that a single failure (e.g., network error, decoding error) does not crash the entire batch process.
- Data Persistence: Save the fetched data (e.g., from BaoStock) to a CSV file using pandas, ensuring the index is not saved (
).index=False
Anti-Patterns
- Do not use a simple
loop for downloading; it must be concurrent.for - Do not omit the
call; the user specifically requested to see the current code in the progress bar.set_postfix - Do not let exceptions propagate out of the thread worker without handling them.
Interaction Workflow
- Define a worker function (e.g.,
) that accepts an item identifier.download_data - Inside the worker, check for file existence, fetch data, save to CSV, and return the identifier.
- Initialize
with a reasonableThreadPoolExecutor
count (e.g., 30).max_workers - Submit all tasks and store futures in a dictionary mapping
tofuture
.identifier - Iterate through
within aas_completed(futures)
context.tqdm - Update the progress bar with
andset_postfix
for each completed future.update(1)
Triggers
- 改成并发下载
- 并发下载股票数据
- tqdm显示进度
- 批量下载股票代码
- 多线程下载baostock