Skip to content

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

Merged
merged 2 commits into from
Apr 28, 2025
Merged

fix: remove username from url only for insta #100

merged 2 commits into from
Apr 28, 2025

Conversation

ovchynnikov
Copy link
Owner

@ovchynnikov ovchynnikov commented Apr 28, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved URL cleaning to ensure only Instagram URLs have trailing usernames removed, leaving other URLs unchanged.
  • Chores

    • Updated the aiohttp dependency to version 3.11.18.

@ovchynnikov ovchynnikov self-assigned this Apr 28, 2025
Copy link
Contributor

coderabbitai bot commented Apr 28, 2025

Walkthrough

The changes include an update to the clean_url function in src/main.py, which now only removes trailing @username segments from URLs containing "instagram.com", rather than from all URLs. Additionally, the version of the aiohttp dependency in src/requirements.txt has been updated from 3.9.3 to 3.11.18. No public API signatures or declarations were altered.

Changes

File(s) Change Summary
src/main.py Modified clean_url to conditionally remove trailing @username only for Instagram URLs.
src/requirements.txt Updated aiohttp version from 3.9.3 to 3.11.18.

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
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 URLs

While the change correctly targets Instagram URLs, there are a few edge cases that might not be handled:

  1. Case sensitivity: URLs with "INSTAGRAM.COM" wouldn't match the current check
  2. 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 handling

For more robust URL handling, consider using the urllib.parse module 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

📥 Commits

Reviewing files that changed from the base of the PR and between b42f098 and 5ee6bc2.

📒 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:


No action needed: aiohttp version is correct

The version 3.11.18 is 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 only

The 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.

@ovchynnikov ovchynnikov merged commit d255788 into main Apr 28, 2025
7 checks passed
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.

1 participant