-
Notifications
You must be signed in to change notification settings - Fork 6
fix: remove username from url only for insta #100
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
Conversation
WalkthroughThe changes include an update to the Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant clean_url
Caller->>clean_url: Provide URL
alt URL contains "instagram.com"
clean_url->>clean_url: Remove trailing @username
else URL does not contain "instagram.com"
clean_url->>clean_url: Leave URL unchanged
end
clean_url-->>Caller: Return cleaned URL
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/main.py (2)
110-130: Consider handling other edge cases for Instagram URLsWhile the change correctly targets Instagram URLs, there are a few edge cases that might not be handled:
- Case sensitivity: URLs with "INSTAGRAM.COM" wouldn't match the current check
- URLs that contain "instagram.com" as a subdomain or path parameter but aren't actual Instagram URLs
Consider using a more robust URL check:
- # Remove any @username from the end of the URL only if it's an Instagram URL - if "instagram.com" in url: - url = url.split('@')[0] + # Remove any @username from the end of the URL only if it's an Instagram URL + if "instagram.com" in url.lower(): + url = url.split('@')[0]
110-130: Consider using a URL parsing library for more robust handlingFor more robust URL handling, consider using the
urllib.parsemodule from the standard library, which would correctly parse and manipulate URL components.+import urllib.parse + def clean_url(message_text: str) -> str: """ Cleans the URL from the message text by removing unwanted characters and usernames. Args: message_text (str): The text of the message containing the URL. Returns: str: The cleaned URL. """ # Remove markdown formatting url = message_text.replace("**", "") # Split by space and take the first part (the URL) url = url.split()[0] - # Remove any @username from the end of the URL only if it's an Instagram URL - if "instagram.com" in url: - url = url.split('@')[0] + # Remove any @username from the end of the URL only if it's an Instagram URL + if "instagram.com" in url.lower(): + parsed_url = urllib.parse.urlparse(url) + # Check if there's an @ in the path and remove everything after it + if '@' in parsed_url.path: + path_parts = parsed_url.path.split('@', 1) + # Reconstruct the URL without the @username part + cleaned_url = urllib.parse.urlunparse(( + parsed_url.scheme, + parsed_url.netloc, + path_parts[0], + parsed_url.params, + parsed_url.query, + parsed_url.fragment + )) + url = cleaned_url return url
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/main.py(1 hunks)src/requirements.txt(1 hunks)
🔇 Additional comments (2)
src/requirements.txt (1)
5-5:✅ Verification successful
Verify the aiohttp version
The version number 3.11.18 seems unusual for aiohttp, which typically follows semantic versioning and the latest stable versions are in the 3.9.x range. This version number doesn't appear to match the standard aiohttp release pattern.
🌐 Web query:
What is the latest version of aiohttp library?💡 Result:
The latest version of the aiohttp library is 3.11.18 as of 2025 [1][2][4]. This version is available on PyPI and includes various bug fixes and enhancements. For any updates or future releases, you can check the official aiohttp repository or documentation.
Citations:
- 1: https://pypi.org/project/aiohttp/
- 2: https://docs.aiohttp.org
- 3: https://github.com/aio-libs/aiohttp/releases
- 4: http://docs.aiohttp.org/en/stable/changes.html
- 5: https://docs.aiohttp.org/en/v3.8.4/changes.html
- 6: https://pypi.org/project/pytest-aiohttp/
- 7: https://github.com/aio-libs/aiohttp
- 8: https://docs.aiohttp.org/en/v3.8.2/
No action needed: aiohttp version is correct
The version
3.11.18is indeed the latest stable release of aiohttp as of 2025, so no update to the dependency is required.src/main.py (1)
126-128: Looks good - fix properly targets Instagram URLs onlyThe change correctly implements the PR objective to remove username from URLs only for Instagram. This ensures that '@username' is only stripped from Instagram URLs, preserving potential legitimate '@' characters in other services' URLs.
Summary by CodeRabbit
Bug Fixes
Chores