news_collector
news_collector
¶
News collection and per-gameweek persistence.
NewsSnapshot
¶
NewsSnapshot(
player_id: int,
gameweek: int,
news_text: str = "",
status: str = "a",
chance_this_round: Optional[float] = None,
chance_next_round: Optional[float] = None,
timestamp: str = "",
)
A single player's news state at a specific gameweek.
| ATTRIBUTE | DESCRIPTION |
|---|---|
player_id |
TYPE:
|
gameweek |
TYPE:
|
news_text |
Raw news string from FPL API.
TYPE:
|
status |
FPL status code: "a", "d", "i", "s", "u", "n".
TYPE:
|
chance_this_round |
Probability of playing this round (0-100 scale from API, stored as 0-1).
TYPE:
|
chance_next_round |
Probability of playing next round (0-1).
TYPE:
|
timestamp |
When the news was added (ISO format from API).
TYPE:
|
Source code in fplx/data/news_collector.py
to_news_signal_input
¶
Convert to the text format that NewsSignal.generate_signal() expects.
Combines the raw news text with status information to give the existing NewsParser richer input.
Source code in fplx/data/news_collector.py
NewsCollector
¶
Collects and persists player news snapshots per gameweek.
Usage (live): collector = NewsCollector(cache_dir="~/.fplx/news") collector.collect_from_bootstrap(bootstrap_data, gameweek=25) # Later, feed into inference: snapshots = collector.get_player_history(player_id=123)
Usage (backtest): collector = NewsCollector(cache_dir="~/.fplx/news") # Load all pre-collected snapshots for gw in range(1, 39): snapshots = collector.get_gameweek(gw) # inject into pipeline per player
| PARAMETER | DESCRIPTION |
|---|---|
cache_dir
|
Directory to persist snapshots as JSON.
TYPE:
|
Source code in fplx/data/news_collector.py
collect_from_bootstrap
¶
Extract news from a bootstrap-static API response.
This is the key method. Call it each gameweek with fresh API data.
| PARAMETER | DESCRIPTION |
|---|---|
bootstrap_data
|
Response from https://fantasy.premierleague.com/api/bootstrap-static/
TYPE:
|
gameweek
|
Current gameweek number.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Number of players with active news. |
Source code in fplx/data/news_collector.py
get_player_news
¶
get_player_news(
player_id: int, gameweek: int
) -> Optional[NewsSnapshot]
Get a specific player's news at a specific gameweek.
Source code in fplx/data/news_collector.py
get_player_history
¶
get_player_history(player_id: int) -> list[NewsSnapshot]
Get all news snapshots for a player across all collected gameweeks.
Returns list sorted by gameweek.
Source code in fplx/data/news_collector.py
get_gameweek
¶
get_gameweek(gameweek: int) -> dict[int, NewsSnapshot]
get_players_with_news
¶
get_players_with_news(gameweek: int) -> list[NewsSnapshot]
Get only players with non-trivial news at a gameweek.
Source code in fplx/data/news_collector.py
collect_season_from_api
¶
Collect news for all gameweeks in a season.
Requires calling the FPL API once per gameweek (the bootstrap-static endpoint only gives current-week news). For backtesting, you'd need to have cached the bootstrap data weekly during the season.
For a single-shot collection (current state only), just call collect_from_bootstrap() once with the current bootstrap data and the current gameweek number.
| PARAMETER | DESCRIPTION |
|---|---|
data_loader
|
Your existing data loader.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
int
|
Number of gameweeks collected. |