Skip to content
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

Refactor Players Search parsing #55

Merged
merged 3 commits into from
Jan 11, 2024

Conversation

felipeall
Copy link
Owner

@felipeall felipeall commented Jan 11, 2024

Summary by CodeRabbit

  • New Features
    • Search results now include player nationalities.
  • Refactor
    • Improved search result parsing for enhanced performance and accuracy.
  • Bug Fixes
    • Search utility now correctly handles optional URLs and text inputs.
    • Test configurations updated to support negative integers.
  • Tests
    • Updated player search tests to reflect changes in the nationality field representation.

Copy link

vercel bot commented Jan 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
transfermarkt-api ✅ Ready (Inspect) Visit Preview Jan 11, 2024 6:17pm

Copy link

coderabbitai bot commented Jan 11, 2024

Walkthrough

The recent updates involve a refactoring of the player search functionality, enhancing the data structure to include player nationalities and improving naming consistency. Utility functions have been updated to handle new parameters and ensure robust text processing. XPath expressions have been redefined to adapt to these changes. Additionally, the testing suite has been adjusted to accommodate the handling of negative integers and the updated structure for player nationalities.

Changes

File Path Change Summary
.../players/search.py Refactored __parse_search_results method to use ElementTree for XML parsing and updated the data structure to include player nationalities with consistent key naming.
.../utils/utils.py Updated extract_from_url to accept an optional tfmkt_url parameter and safe_regex to accept a Union[str, list] for text, with both utilizing the trim function for processing.
.../utils/xpath.py Removed FOUND attribute and added RESULTS and NATIONALITIES in the Profile class's Search nested class. Redefined various attributes with new XPath expressions.
tests/conftest.py Modified regex_integer fixture to support negative integers.
tests/players/test_players_search.py Updated tests to expect a list for nationalities instead of a string.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7b97d3e and e25a924.
Files selected for processing (5)
  • app/services/players/search.py (2 hunks)
  • app/utils/utils.py (5 hunks)
  • app/utils/xpath.py (1 hunks)
  • tests/conftest.py (1 hunks)
  • tests/players/test_players_search.py (1 hunks)
Additional comments: 6
tests/players/test_players_search.py (1)
  • 46-46: The update to the test schema to expect a list of nationalities instead of a single string is correct and aligns with the changes made in the PR.
app/services/players/search.py (2)
  • 42-42: Please clarify the usage of self.page.xpath. The xpath method is not a standard method on ElementTree objects. If self.page is an ElementTree object, you should use ElementTree.findall() or similar methods provided by ElementTree for XPath expressions.

  • 45-66: The changes to the __parse_search_results method correctly reflect the updated data structure and naming convention for the player search results.

app/utils/utils.py (2)
  • 48-56: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [40-64]

The changes to the extract_from_url function correctly handle the new optional tfmkt_url parameter by returning None if it is not provided.

  • 95-105: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [86-102]

The changes to the safe_regex function correctly handle the new text parameter type and ensure safe processing by checking if text is a string or a list and not empty before proceeding.

app/utils/xpath.py (1)
  • 47-56: The changes to the Search nested class, including the removal of the FOUND attribute and the addition of new attributes RESULTS and NATIONALITIES, correctly reflect the updated XPath expressions and align with the PR objectives.

@@ -34,7 +34,7 @@ def regex_value_variation():

@pytest.fixture
def regex_integer():
return Regex(r"^\d+$")
return Regex(r"^(\d+|-)$")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern for matching integers is incorrect. It currently matches a single hyphen or a sequence of digits, but it does not match negative integers. Here's a corrected version:

- return Regex(r"^(\d+|-)$")
+ return Regex(r"^-?\d+$")

This pattern will match any integer, positive or negative, as intended.


Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
return Regex(r"^(\d+|-)$")
return Regex(r"^-?\d+$")

@felipeall felipeall merged commit 0d7bf48 into main Jan 11, 2024
3 checks passed
@felipeall felipeall deleted the players/search/refactor-results-parsing branch January 11, 2024 18:20
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