Why Did I Build This?
"Machine learning pipelines require massive, highly structured datasets, but public APIs like Jikan enforce strict rate limits and suffer from unpredictable downtime. I engineered this robust scraping infrastructure to autonomously harvest raw data for future model training, ensuring absolutely zero data loss during multi-hour execution cycles."
Architecture & Decisions
The script operates entirely on Python, utilizing `requests` for network I/O and `pandas` for DataFrame manipulation. The core execution loop implements a resilient retry mechanism equipped with exponential backoff and randomized jitter to seamlessly absorb HTTP 429 (Too Many Requests) and 5xx server errors. To guarantee data integrity during potential OS crashes or exhaustive long-running tasks, file descriptors are forcibly flushed directly to disk using the low-level `os.fsync()` system call after every pagination cycle. Standard output (stdout) is dynamically intercepted and routed into a multi-channel structured logging architecture.
Key Features
- 01.Aggressive HTTP 429 rate-limit mitigation via an exponential backoff algorithm integrated with randomized jitter
- 02.Absolute persistence of incremental DataFrame writes guaranteed by OS-level file syncing (`os.fsync`)
- 03.Dual-depth CSV exporting strategy (core metrics vs. complex entity relationships) pre-optimized for ML feature engineering
- 04.Autonomous error-handling and dead-letter logging mechanisms to isolate network disconnects and malformed JSON payloads