agentsclimarketplace

并发下载股票数据并显示进度

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8/并发下载股票数据并显示进度

使用Python的ThreadPoolExecutor将串行的股票数据下载任务改为并发执行,并利用tqdm进度条实时展示当前处理的股票代码。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill 并发下载股票数据并显示进度

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.9 KB, 576 tokens by cl100k_base, as published. Nobody here has run it

并发下载股票数据并显示进度

使用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

  1. Concurrency: Use concurrent.futures.ThreadPoolExecutor to manage concurrent download tasks.
  2. Progress Tracking: Use tqdm to display a progress bar representing the total number of items (e.g., stock codes) to be processed.
  3. Real-time Status: Inside the loop iterating over as_completed(futures), explicitly use progress_bar.set_postfix({'code': code}) to display the specific identifier (e.g., stock code) of the currently completed task.
  4. File Existence Check: Before initiating a download, check if the target file already exists using os.path.exists. If it exists, skip the download to save bandwidth and time.
  5. 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.
  6. 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 for loop for downloading; it must be concurrent.
  • Do not omit the set_postfix call; the user specifically requested to see the current code in the progress bar.
  • Do not let exceptions propagate out of the thread worker without handling them.

Interaction Workflow

  1. Define a worker function (e.g., download_data) that accepts an item identifier.
  2. Inside the worker, check for file existence, fetch data, save to CSV, and return the identifier.
  3. Initialize ThreadPoolExecutor with a reasonable max_workers count (e.g., 30).
  4. Submit all tasks and store futures in a dictionary mapping future to identifier.
  5. Iterate through as_completed(futures) within a tqdm context.
  6. Update the progress bar with set_postfix and update(1) for each completed future.

Triggers

  • 改成并发下载
  • 并发下载股票数据
  • tqdm显示进度
  • 批量下载股票代码
  • 多线程下载baostock

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.