forked from dogsheep/pocket-to-sqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Comprehensive fixes: API connectivity, error handling, retry logic, and progress tracking #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Replace dict access with .get() method to handle missing keys gracefully - Add comprehensive tests for both missing 'list' and 'since' key scenarios - Prevents crashes when Pocket API returns unexpected response format Fixes the stack trace: KeyError: 'list' at utils.py line 119 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add check for items table existence before enabling FTS - Add comprehensive tests for ensure_fts function edge cases: * When no items table exists (should not crash) * When items table exists (should create FTS) * When FTS already exists (should skip creation) Fixes the stack trace: sqlite3.OperationalError: no such table: items at utils.py line 68 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Change requests.get() to requests.post() for /v3/get endpoint - Change requests.get() to requests.post() for /v3/stats endpoint - Restore full progress bar functionality with total item count - /v3/stats endpoint is functional but undocumented The core issue was HTTP method, not deprecated endpoints. All API calls now use POST as required by Pocket API. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
0f3d51a to
3e2907f
Compare
- Add --debug flag to enable detailed logging - Log API requests, responses, and item processing - Track offset progression and item counts - Help identify why articles aren't being fetched 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Add proper Content-Type headers for API requests
- Use 'data' parameter instead of passing args directly to requests.post()
- Add error detection and logging for API error responses
- Update tests to use requests.post instead of requests.get
- Add test coverage for API error handling
Fixes the issue where API returns {'error': '...'} instead of data.
The Pocket API requires proper form-encoded requests with headers.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Reduce default page size from 500 to 50 items - Add automatic fallback mechanism for 413 errors: * Detect 'Payload Too Large' errors * Automatically reduce page size by half (minimum 10) * Retry with smaller page size - Add comprehensive test coverage for 413 error handling - Continue processing with reduced page size instead of crashing Fixes the issue where large accounts cause 413 errors due to excessive payload size when requesting complete item details. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- Change error detection from checking key existence to checking value
- Only treat as error if error key has non-None value
- Add test for success case with 'error': None in response
- Fixes false positive error detection when API returns success
The Pocket API returns {'error': None, 'list': {...}} for successful
responses, so we need to check the error value, not just key presence.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Handle numeric author_ids normally (existing schema) - For string author_ids (alternative schema): * Treat the string as the author name * Generate deterministic integer ID using MD5 hash * Maintain integer author_id constraint in database - Add comprehensive test coverage for: * String author IDs become names with generated IDs * Mixed numeric/string author IDs in same item * Consistent ID generation for same string values Supports ~5-10% of Pocket items that use alternative author schema without breaking existing database structure or functionality. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2b5f7cf to
f2a6519
Compare
…tamps - Replace timestamp-based 'since' parameter with offset-based approach - Track number of existing items in database for incremental fetching - Start fetching from offset = count of existing items - Remove problematic since/timestamp logic that wasn't working - Add test coverage for start_offset functionality This properly resumes fetching from where it left off by continuing pagination from the number of items already stored in the database. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
7f490a7 to
4277c4d
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR comprehensively fixes the pocket-to-sqlite tool, addressing multiple critical issues that prevented it from working with the current Pocket API. The changes transform a broken tool into a robust, production-ready application with proper error handling, retry logic, and progress tracking.
Issues Fixed
1. 🔧 API Connectivity & Request Format
2. 🛡️ Error Handling & Resilience
3. 📊 Data Processing & Schema Support
4. 🔄 Incremental Fetching & Progress Tracking
Technical Improvements
Robust Error Handling
Progressive Retry Logic
Smart Data Processing
Accurate Progress Tracking
Changes Made
Core Functionality (
utils.py)CLI Interface (
cli.py)Comprehensive Testing (
tests/test_save_pocket.py)Test Coverage
Before vs After
Before: Tool was completely broken with multiple crash points
After: Robust, production-ready tool with:
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com