A Python tool that aggregates the P2P.org documentation, downloads Markdown files concurrently, and aggregates them into a single, navigable document with table of contents.
This script:
- Fetches a list of Markdown links from
https://docs.p2p.org/llms.txt - Downloads all linked Markdown files concurrently
- Saves individual Markdown files in a
markdown_filesdirectory - Aggregates all content into a single Markdown file with a table of contents
- Logs detailed information about the scraping process
- Python 3.6+
- Required packages:
requeststqdm
-
Clone this repository:
git clone https://github.com/AndreGZommerfelds/p2p-docs-aggregator.git cd p2p-docs-aggregator -
Install required packages:
pip install -r requirements.txt
Run the script with:
python scrape_p2p_docs.py
Alternatively, use the provided shell script, which sets up a virtual environment and installs dependencies:
./run_scraper.sh
The script produces the following:
p2p_aggregated_docs.md: The aggregated documentation filemarkdown_files/: Directory containing individual Markdown filesscraper.log: Detailed logging informationfailed_urls.txt: List of URLs that failed to download (if any)
You can modify the following constants in the script:
MAX_WORKERS: Number of concurrent downloads (default: 5)MAX_RETRIES: Number of retry attempts for failed requests (default: 3)TIMEOUT: Request timeout in seconds (default: 10)OUTPUT_FILE: Name of the aggregated output file (default: "p2p_aggregated_docs.md")
- Concurrent Downloads: Uses ThreadPoolExecutor for efficient downloading
- Progress Tracking: Shows a progress bar for downloads using tqdm
- Robust Error Handling: Implements retry logic with exponential backoff
- Rate Limiting: Controls concurrent requests to avoid overwhelming the server
- Detailed Logging: Logs all actions and errors for troubleshooting
- Table of Contents: Generates a navigable table of contents in the output file
MIT