toutatis
toutatis copied to clipboard
Refactor core functionality and improve error handling with version bump to 1.32
This PR introduces several key improvements to the Toutatis codebase:
๐ง Refactoring & Code Structure
-
Refactored main function: Split the original
main()function intoprocess_request()for better separation of concerns and improved testability - Updated entry point logic: Reorganized script execution flow to follow Python best practices
-
Removed redundant imports: Cleaned up unused imports (
argparsemoved to appropriate scope, removed unusedregion_code_for_number)
๐ก๏ธ Enhanced Error Handling
- Improved JSON parsing: Added robust error handling for API responses with proper null checks
- Better user not found scenarios: Enhanced detection and handling of missing user data from Instagram API
-
Defensive programming: Added
.get()method calls with fallback values to prevent KeyError exceptions - Safer data access: Wrapped potentially missing dictionary keys with proper defaults
๐ Code Quality Improvements
- More robust parsing logic: Improved handling of user information output with better null safety
- Cleaner output formatting: Enhanced display logic for optional fields like external URLs, emails, and phone numbers
-
Better variable naming: Used more descriptive variable names (
_idinstead ofidto avoid shadowing builtin)
๐ฆ Version Management
-
Version bump: Updated package version from 1.31 to 1.32 in
setup.py
๐งช Maintainability
- Improved function organization: Better separation between CLI handling and core processing logic
- Enhanced readability: More consistent code style and better structured conditional logic
These changes make the codebase more robust, maintainable, and less prone to runtime errors when dealing with varying Instagram API responses.