feat: Add Excel export functionality and unit tests

Features:
- Excel export with formatted multi-sheet workbooks (Contents, Comments, Creators)
- Professional styling: blue headers, auto-width columns, borders, text wrapping
- Smart export: empty sheets automatically removed
- Support for all platforms (xhs, dy, ks, bili, wb, tieba, zhihu)

Testing:
- Added pytest framework with asyncio support
- Unit tests for Excel store functionality
- Unit tests for store factory pattern
- Shared fixtures for test data
- Test coverage for edge cases

Documentation:
- Comprehensive Excel export guide (docs/excel_export_guide.md)
- Updated README.md and README_en.md with Excel examples
- Updated config comments to include excel option

Dependencies:
- Added openpyxl>=3.1.2 for Excel support
- Added pytest>=7.4.0 and pytest-asyncio>=0.21.0 for testing

This contribution adds immediate value for users who need data analysis
capabilities and establishes a testing foundation for future development.
This commit is contained in:
hsparks.codes
2025-11-28 04:44:12 +01:00
parent 31a092c653
commit 46ef86ddef
14 changed files with 881 additions and 4 deletions
+9
View File
@@ -37,6 +37,7 @@ from tools.time_util import get_current_timestamp
from var import crawler_type_var
from database.mongodb_store_base import MongoDBStoreBase
from tools import utils
from store.excel_store_base import ExcelStoreBase
class XhsCsvStoreImplement(AbstractStore):
def __init__(self, **kwargs):
@@ -336,3 +337,11 @@ class XhsMongoStoreImplement(AbstractStore):
data=creator_item
)
utils.logger.info(f"[XhsMongoStoreImplement.store_creator] Saved creator {user_id} to MongoDB")
class XhsExcelStoreImplement(ExcelStoreBase):
"""小红书Excel存储实现"""
def __init__(self, **kwargs):
super().__init__(platform="xhs", crawler_type=crawler_type_var.get())
utils.logger.info("[XhsExcelStoreImplement] Excel store initialized")