fix: support biz_message_N.db filename pattern in export_messages.py#7
fix: support biz_message_N.db filename pattern in export_messages.py#7Techeek wants to merge 1 commit intoThearas:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical issue in the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly extends the get_all_msg_dbs function to support the biz_message_N.db filename pattern, in addition to the existing message_N.db pattern. The change is simple and effective. I've added one suggestion to refactor the function for better readability and to remove a redundant import, following Python best practices.
| import re | ||
| msg_dir = os.path.join(decrypted_dir, "message") | ||
| if not os.path.isdir(msg_dir): | ||
| return [] | ||
| dbs = [] | ||
| for f in sorted(os.listdir(msg_dir)): | ||
| if re.match(r"^message_\d+\.db$", f): | ||
| if re.match(r"^(biz_)?message_\d+\.db$", f): | ||
| dbs.append(os.path.join(msg_dir, f)) | ||
| return dbs |
There was a problem hiding this comment.
This function can be refactored for better readability and to follow Python best practices:
- The
import restatement is redundant becausereis already imported at the top of the file. Per PEP 8, imports should be at the module level. - The loop that builds the
dbslist can be replaced with a more concise list comprehension.
Here's a suggested implementation that applies these improvements.
| import re | |
| msg_dir = os.path.join(decrypted_dir, "message") | |
| if not os.path.isdir(msg_dir): | |
| return [] | |
| dbs = [] | |
| for f in sorted(os.listdir(msg_dir)): | |
| if re.match(r"^message_\d+\.db$", f): | |
| if re.match(r"^(biz_)?message_\d+\.db$", f): | |
| dbs.append(os.path.join(msg_dir, f)) | |
| return dbs | |
| msg_dir = os.path.join(decrypted_dir, "message") | |
| if not os.path.isdir(msg_dir): | |
| return [] | |
| dbs = [ | |
| os.path.join(msg_dir, f) | |
| for f in sorted(os.listdir(msg_dir)) | |
| if re.match(r"^(biz_)?message_\d+\.db$", f) | |
| ] | |
| return dbs |
References
- PEP 8 style guide suggests that imports should be placed at the top of the module, not inside functions, to improve clarity and avoid issues with module loading. (link)
There was a problem hiding this comment.
Pull request overview
Updates message database discovery to support newer WeChat for macOS naming, so exports work when decrypted DBs are named with the biz_ prefix.
Changes:
- Expand
get_all_msg_dbs()filename matching to includebiz_message_N.db. - Update the function docstring to reflect the supported filename patterns.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| dbs = [] | ||
| for f in sorted(os.listdir(msg_dir)): | ||
| if re.match(r"^message_\d+\.db$", f): | ||
| if re.match(r"^(biz_)?message_\d+\.db$", f): | ||
| dbs.append(os.path.join(msg_dir, f)) |
There was a problem hiding this comment.
The message DB filename matching logic is duplicated elsewhere (e.g., mcp_server.py:get_msg_dbs still only matches ^message\d+.db$). This change fixes export_messages.py but leaves other entry points potentially broken on newer WeChat macOS versions; consider updating the other helper(s) as well or centralizing the pattern to avoid future divergence.
Problem
export_messages.py failed with '[-] No message databases found in decrypted/message/' because get_all_msg_dbs() only matched message_N.db filenames, but newer versions of WeChat for macOS name the databases biz_message_N.db instead.
Fix
Updated the regex in get_all_msg_dbs() from ^message_\d+.db$ to ^(biz_)?message_\d+.db$ to match both message_0.db and biz_message_0.db patterns.