Skip to content

Modernize MNB Exchange Rate Script to v2.0#3

Open
peter-oroszvari wants to merge 6 commits intobelidzs:developfrom
peter-oroszvari:claude/repo-review-011CUoUDiQFLAG29fgEUpUHH
Open

Modernize MNB Exchange Rate Script to v2.0#3
peter-oroszvari wants to merge 6 commits intobelidzs:developfrom
peter-oroszvari:claude/repo-review-011CUoUDiQFLAG29fgEUpUHH

Conversation

@peter-oroszvari
Copy link
Copy Markdown

This PR comprehensively modernizes the MNB exchange rate fetcher from a simple proof-of-concept into a production-ready Python application with modern best practices and extensive new functionality.

Key Improvements
🚀 Code Quality
✅ Full type hints throughout the codebase (PEP 484)
✅ Dataclasses for type-safe data handling
✅ Comprehensive error handling with custom MNBClientError exception
✅ Robust logging system with configurable levels (INFO/ERROR/DEBUG)
✅ Clean separation of concerns (MNBClient, XMLParser, OutputFormatter)
✅ Complete docstrings following Google style
✨ New Features
✅ Flexible CLI with argparse supporting multiple options
✅ Multiple output formats: table (default), JSON, CSV
✅ File output support with --output flag
✅ Historical exchange rate queries with --historical
✅ Verbose logging mode with --verbose
✅ Custom WSDL URL support for testing
✅ Script is now importable as a reusable library
📦 Dependencies & Testing
✅ Updated zeep: 3.2.0 → 4.3.2
✅ Updated lxml to 6.0+
✅ Added pytest test suite with 18 tests (all passing ✅)
✅ Added development requirements (pytest, black, mypy, ruff)
📝 Documentation
✅ Complete README rewrite with modern examples
✅ Installation and usage instructions
✅ CLI options reference
✅ Library usage examples
✅ Architecture overview
✅ Comprehensive changelog
Usage Examples
Current rates (backward compatible - works exactly like before)
python mnb.py
New capabilities

JSON output

python mnb.py --format json

CSV output

python mnb.py --format csv

Historical EUR rates

python mnb.py --historical --currency EUR --start 2024-01-01 --end 2024-12-31

Save to file

python mnb.py --format json --output rates.json

Verbose logging

python mnb.py --verbose
Library usage
from mnb import MNBClient, XMLParser

client = MNBClient()
parser = XMLParser()

xml_data = client.get_current_exchange_rates()
exchange_rates = parser.parse_current_rates(xml_data)

for rate in exchange_rates.rates:
print(f"{rate.currency}: {rate.rate}")
Testing
All 18 unit tests pass successfully.

Changes Summary
📝 5 files changed
➕ 993 insertions
➖ 357 deletions
🆕 2 new files: requirements-dev.txt, test_mnb.py
Backward Compatibility
✅ Fully backward compatible - The script maintains its original behavior when run without arguments. All original functionality works as before.

Checklist

Code follows modern Python best practices

All tests pass

Documentation is complete and accurate

Backward compatibility maintained

Dependencies updated to latest stable versions

Error handling is comprehensive

Code is well-documented with docstrings and type hints

peter-oroszvari and others added 6 commits December 28, 2022 20:50
Retrieve USD exchange rates of a period (2022-01-01 - 2022-12-28)
Code refactor
Output update
Moved process_xml function into the XMLParser class
This comprehensive modernization update transforms the script from a simple
proof-of-concept into a production-ready Python application with modern best
practices and extensive functionality.

Major improvements:
- Add full type hints and dataclasses for type safety
- Implement comprehensive error handling with custom exceptions
- Refactor code with clean separation of concerns (Client, Parser, Formatter)
- Add flexible CLI with argparse supporting multiple options
- Support multiple output formats (table, JSON, CSV)
- Add complete docstrings following Google style
- Implement robust logging system with configurable levels
- Make script importable as a reusable library
- Update dependencies to latest versions (zeep 4.3.2, lxml 6.0+)

New features:
- Command-line arguments for output format, file saving, historical queries
- JSON and CSV output formats in addition to table format
- Verbose logging mode for debugging
- Custom WSDL URL support for testing
- File output support with --output flag

Testing & quality:
- Add comprehensive pytest test suite with 18 tests
- Add development requirements (pytest, black, mypy, ruff)
- All tests passing with good coverage

Documentation:
- Complete rewrite of README with modern examples
- Add installation instructions and usage examples
- Document all CLI options and library usage
- Add architecture overview and API reference
- Include changelog documenting all improvements

The script maintains backward compatibility while adding extensive new
functionality. All original features work as before, with the default
behavior unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants