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

change schedule scrape helper to include offdays #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JackLich10
Copy link

@JackLich10 JackLich10 commented Jan 31, 2025

Summary by CodeRabbit

  • New Features
    • Enhanced ESPN women's basketball calendar retrieval to support both on-days and off-days
    • Improved data collection by fetching from multiple endpoints
    • Ensured unique calendar entries by removing duplicate URLs

Copy link

vercel bot commented Jan 31, 2025

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

Name Status Preview Comments Updated (UTC)
sportsdataverse-py ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 31, 2025 2:10pm

Copy link

coderabbitai bot commented Jan 31, 2025

Walkthrough

The changes modify the ESPN Women's Basketball (WBB) calendar retrieval functionality in the sportsdataverse library. The primary modification involves renaming the ondays parameter to onoffdays in the espn_wbb_calendar function and updating the underlying helper function to fetch data for both on-days and off-days. The new implementation constructs two separate URLs, downloads data from both endpoints, and concatenates the results into a single DataFrame with unique URLs.

Changes

File Change Summary
sportsdataverse/wbb/wbb_schedule.py - Renamed ondays parameter to onoffdays in espn_wbb_calendar function
- Replaced __ondays_wbb_calendar with __onoffdays_wbb_calendar
- Updated function to fetch data from both on-days and off-days URLs
- Added .unique(subset="url") to ensure unique DataFrame entries

Sequence Diagram

sequenceDiagram
    participant User
    participant espn_wbb_calendar
    participant __onoffdays_wbb_calendar
    participant ESPN API

    User->>espn_wbb_calendar: Call with season, onoffdays
    espn_wbb_calendar->>__onoffdays_wbb_calendar: Request calendar data
    __onoffdays_wbb_calendar->>ESPN API: Fetch on-days URL
    __onoffdays_wbb_calendar->>ESPN API: Fetch off-days URL
    ESPN API-->>__onoffdays_wbb_calendar: Return data
    __onoffdays_wbb_calendar->>__onoffdays_wbb_calendar: Concatenate DataFrames
    __onoffdays_wbb_calendar->>__onoffdays_wbb_calendar: Remove duplicate URLs
    __onoffdays_wbb_calendar-->>espn_wbb_calendar: Return unique calendar data
    espn_wbb_calendar-->>User: Return calendar DataFrame
Loading

Poem

🏀 Hops of Data, Bouncing Free 🏀

In the court of schedules, a rabbit's glee,
On-days, off-days, now dancing with me,
URLs unique, no duplicates in sight,
ESPN's calendar, a computational delight!

Hop, hop, hooray! 🐰✨

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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>, 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. (Beta)
  • @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

@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 (1)
sportsdataverse/wbb/wbb_schedule.py (1)

185-200: Add error handling and consider performance optimization.

While the implementation is functional, consider these improvements:

  1. Error Handling:

    • Add error handling for failed API requests.
    • Validate response data structure before accessing nested fields.
  2. Performance:

    • Consider parallelizing the API calls to reduce latency.

Here's a suggested implementation with error handling and parallel requests:

 def __onoffdays_wbb_calendar(season, **kwargs):
+    import concurrent.futures
+    import functools
+
+    def fetch_calendar(url, **kwargs):
+        try:
+            resp = download(url=url, **kwargs)
+            data = resp.json()
+            if not data or 'eventDate' not in data or 'dates' not in data['eventDate']:
+                return []
+            return data['eventDate']['dates']
+        except Exception as e:
+            print(f"Error fetching calendar data: {e}")
+            return []
+
     url_on = f"https://sports.core.api.espn.com/v2/sports/basketball/leagues/womens-college-basketball/seasons/{season}/types/2/calendar/ondays"
     url_off = f"https://sports.core.api.espn.com/v2/sports/basketball/leagues/womens-college-basketball/seasons/{season}/types/2/calendar/offdays"
-    resp_on = download(url=url_on, **kwargs)
-    txt_on = resp_on.json().get("eventDate").get("dates")
-    url_off = f"https://sports.core.api.espn.com/v2/sports/basketball/leagues/womens-college-basketball/seasons/{season}/types/2/calendar/offdays"
-    resp_off = download(url=url_off, **kwargs)
-    txt_off = resp_off.json().get("eventDate").get("dates")
+
+    with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
+        fetch_with_kwargs = functools.partial(fetch_calendar, **kwargs)
+        futures = [
+            executor.submit(fetch_with_kwargs, url_on),
+            executor.submit(fetch_with_kwargs, url_off)
+        ]
+        txt_on, txt_off = [f.result() for f in futures]
+
     result = pl.concat(
         [pl.DataFrame(txt_on, schema=["dates"]), pl.DataFrame(txt_off, schema=["dates"])],
         how="diagonal_relaxed"
     )
+    if result.height == 0:
+        return pl.DataFrame(schema={"dates": pl.Utf8, "dateURL": pl.Utf8, "url": pl.Utf8})
+
     result = result.with_columns(dateURL=pl.col("dates").str.slice(0, 10))
     result = result.with_columns(
         url="http://site.api.espn.com/apis/site/v2/sports/basketball/womens-college-basketball/scoreboard?dates="
         + pl.col("dateURL")
     ).unique(subset="url")
     return result
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8f757d3 and 5dd4563.

📒 Files selected for processing (1)
  • sportsdataverse/wbb/wbb_schedule.py (3 hunks)
🔇 Additional comments (2)
sportsdataverse/wbb/wbb_schedule.py (2)

141-146: LGTM! Parameter rename and docstring update are clear.

The parameter rename from ondays to onoffdays better reflects its expanded functionality to handle both on-days and off-days.


157-158: LGTM! Implementation changes are consistent.

The condition and helper function call have been correctly updated to use the renamed parameter.

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