Skip to content

Conversation

touchmeangel
Copy link

@touchmeangel touchmeangel commented Oct 4, 2025

Check issue #389. Updated from guilds.json to GenericTimelineById

Summary by Sourcery

Switch get_trends to use the GenericTimelineById GraphQL endpoint instead of the legacy v1.1 guide API, introduce feature flags and helper methods for explore_page and generic_timeline_by_id, add a mapping of timeline IDs for trending categories, and update the Trend model to parse snake_case fields from the new response.

Enhancements:

  • Introduce EXPLORE_PAGE and GENERIC_TIMELINE_BY_ID GraphQL endpoints and corresponding client methods
  • Add EXPLORE_PAGE_FEATURES, GENERIC_TIMELINE_FEATURES feature-flag constants and TIMELINE_IDS mapping for trend categories
  • Refactor get_trends to retrieve trends via generic_timeline_by_id and simplify category handling

Summary by CodeRabbit

  • New Features

    • Expanded Trends categories and improved timeline-based trend retrieval for broader coverage.
  • Bug Fixes

    • Graceful handling of unknown trend categories (returns empty results) and more reliable retries/fallbacks when no trends are found.
  • Refactor

    • Trend data keys moved to snake_case (e.g., trend_metadata, meta_description, domain_context, grouped_trends); tweets_count now represented as a string.
  • Chores

    • Updated ignore rules to exclude Python bytecode.

Copy link

sourcery-ai bot commented Oct 4, 2025

Reviewer's Guide

This PR replaces the old v11 guide-based trends fetch with a GraphQL GenericTimelineById call, adding new endpoints, feature-flag maps, and updating the Trend model to align with the new response shape.

Sequence diagram for updated get_trends flow using GenericTimelineById

sequenceDiagram
    participant Client
    participant GQL
    participant "GenericTimelineById Endpoint"
    participant Trend
    Client->>GQL: generic_timeline_by_id(timeline_id, count)
    GQL->>"GenericTimelineById Endpoint": gql_get(...)
    "GenericTimelineById Endpoint"-->>GQL: Response (entries)
    GQL-->>Client: Response (entries)
    loop For each entry
        Client->>Trend: Trend(self, entry['content']['itemContent'])
    end
    Client-->>Client: Return list of Trend objects
Loading

Updated class diagram for Trend model

classDiagram
    class Trend {
        - _client: Client
        - name: str
        - tweets_count: str | None
        - domain_context: str
        - grouped_trends: list[str]
        + __init__(client: Client, data: dict)
        + __repr__() -> str
    }
    Trend <-- Client
Loading

Class diagram for new GQL methods and endpoint constants

classDiagram
    class GQL {
        + explore_page()
        + generic_timeline_by_id(timeline_id, count)
    }
    class Endpoint {
        + EXPLORE_PAGE
        + GENERIC_TIMELINE_BY_ID
    }
    GQL --> Endpoint
Loading

File-Level Changes

Change Details Files
Refactor get_trends to use GenericTimelineById
  • Map input category to timeline_id via TIMELINE_IDS
  • Replace v11.guide call with gql.generic_timeline_by_id
  • Early-return empty list when timeline_id is missing
  • Adjust retry logic indentation
  • Filter entries by 'trend' prefix and build Trend objects
twikit/client/client.py
Add new GraphQL endpoints and client methods
  • Introduce EXPLORE_PAGE and GENERIC_TIMELINE_BY_ID endpoints
  • Implement explore_page() with EXPLORE_PAGE_FEATURES
  • Implement generic_timeline_by_id() with GENERIC_TIMELINE_FEATURES
twikit/client/gql.py
Define feature-flag constants and timeline IDs
  • Add EXPLORE_PAGE_FEATURES and GENERIC_TIMELINE_FEATURES maps
  • Add TIMELINE_IDS mapping for trending categories
twikit/constants.py
Update Trend model to match new API schema
  • Rename trendMetadata to trend_metadata and related fields
  • Rename metaDescription/domainContext/groupedTrends keys
  • Adjust tweets_count type and TODO-int conversion
twikit/trend.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

coderabbitai bot commented Oct 4, 2025

Walkthrough

Shifts trends retrieval from v11.guide to a timeline-id driven GraphQL flow, adding new endpoints and feature-flag constants, updating response parsing and retry logic, renaming trend fields to snake_case, and updating .gitignore to ignore Python bytecode.

Changes

Cohort / File(s) Summary of edits
Trends timeline migration
twikit/client/client.py, twikit/client/gql.py, twikit/constants.py
Replace v11.guide usage with timeline-id driven fetch via new Endpoint entries; add EXPLORE_PAGE_FEATURES and GENERIC_TIMELINE_FEATURES; add TIMELINE_IDS mapping; implement generic_timeline_by_id and explore_page GQL calls; client uses timeline IDs, filters entries by entryId prefix, adjusts parsing path and retry/fallback logic.
Trend data shape adjustments
twikit/trend.py
Rename keys to snake_case (trend_metadata, meta_description, domain_context, grouped_trends); adjust tweets_count to `str
Ignore updates
.gitignore
Add __pycache__ to ignores; reaffirm /node_modules entry.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as Caller
  participant C as Client.get_trends(category, count, retry)
  participant K as Constants (TIMELINE_IDS, FEATURES)
  participant G as GQLClient
  participant E as Endpoint.GENERIC_TIMELINE_BY_ID
  participant P as Trend parser

  U->>C: get_trends(category, count, retry)
  C->>K: Lookup timeline_id = TIMELINE_IDS[category]
  alt Unknown category
    C-->>U: []
  else Known category
    C->>G: generic_timeline_by_id(timeline_id, count, FEATURES)
    G->>E: Request (id, count, features)
    E-->>G: Response (entries)
    G-->>C: entries
    C->>C: Filter entries with entryId starting "trend"
    alt No trend entries and retry
      C->>C: Recursive get_trends(category, count, retry=false)
      C-->>U: Result
    else Have trend entries
      C->>P: Build Trend objects from entry.content.itemContent
      P-->>C: Trend[]
      C-->>U: Trend[]
    end
  end

  rect rgba(200,230,255,0.25)
    note right of E: New timeline-id GraphQL flow replaces v11.guide
  end
  rect rgba(220,255,220,0.18)
    note right of C: Updated parsing path and retry behavior
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

I thump my paws on timelines new,
IDs tucked safe in fur of dew,
Trends hop out in tidy rows,
Snake_case whispers where code glows,
Bytecode bunnies nap in view. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title Check ❓ Inconclusive The title “get_trends deprecation update/fix” is too generic and does not clearly convey the primary change of migrating get_trends from the legacy guide API to the new GenericTimelineById GraphQL endpoint. It uses vague terms like “update/fix” without specifying the core migration or deprecation context. Consider renaming the title to explicitly reference the migration, for example “Migrate get_trends to use GenericTimelineById GraphQL endpoint” to clearly highlight the main change.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ace371 and ed6c000.

📒 Files selected for processing (1)
  • twikit/client/client.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
twikit/client/client.py (2)
twikit/client/gql.py (1)
  • generic_timeline_by_id (312-317)
twikit/utils.py (1)
  • find_dict (111-127)

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@touchmeangel touchmeangel changed the title get_trends update/fix get_trends deprecation update/fix Oct 4, 2025
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b18105 and 9ace371.

📒 Files selected for processing (5)
  • .gitignore (1 hunks)
  • twikit/client/client.py (2 hunks)
  • twikit/client/gql.py (3 hunks)
  • twikit/constants.py (1 hunks)
  • twikit/trend.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
twikit/client/client.py (2)
twikit/client/gql.py (1)
  • generic_timeline_by_id (312-317)
twikit/utils.py (1)
  • find_dict (111-127)
twikit/client/gql.py (1)
twikit/client/v11.py (1)
  • Endpoint (14-50)

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