The Premier League is back, which also means Fantasy Premier League is back. When our workplace league grew to more than 20 people, I wanted a better way to keep the weekly chat lively with proper analysis and banter.
The problem was simple: manually checking every team, tracking transfers, spotting captain wins, and working out who had played which chip was taking far too long. That was time better spent stressing over my own transfers.
So I automated it.
The Lightbulb Moment
After about 45 minutes of manually trawling through teams and gameweek results, the obvious question hit me: there has to be a better way.
That was when I remembered two useful facts:
- The FPL API exists
- I already know how to script in PowerShell
That combination was enough to build a workflow that could collect the data I needed, structure it properly, and generate a polished weekly summary.
Writing the Script
The FPL API is surprisingly usable once you find the right endpoints. The key pieces were:
- League standings
- Individual team picks
- Live gameweek points
- The player database
Pulling the data itself was straightforward with PowerShell:
# This gets you the league table
$leagueUrl = "https://fantasy.premierleague.com/api/leagues-classic/$leagueId/standings/"
$leagueData = Invoke-RestMethod -Uri $leagueUrl
# And this gets the juicy details for each team
foreach ($team in $leagueData.standings.results) {
$teamUrl = "https://fantasy.premierleague.com/api/entry/$($team.entry)/event/$gameweek/picks/"
$picksData = Invoke-RestMethod -Uri $teamUrl
# Now we've got everything...
}
The real challenge was not collecting the data. It was understanding the quirks that make Fantasy Premier League interesting:
- Triple Captain changing captain scoring
- Bench Boost bringing bench players into the total
- Free Hit temporarily changing a team
- Rank movement from one gameweek to the next
With some help from GitHub Copilot, I built out a script that handled those cases and turned messy API responses into something structured and useful.
Using AI for the Better Good
Once the data was organised, the next step was obvious: let Azure OpenAI write the weekly analysis.
Instead of manually phrasing every observation, I could feed the model a JSON payload containing the weekly highlights and ask it to generate a friendly workplace-style summary that still captured the FPL drama.
$messages = @(
@{
role = 'system'
content = "You're analyzing Fantasy Premier League data for a workplace league. Be engaging, slightly competitive, but keep it friendly..."
},
@{
role = 'user'
content = "Here's this week's data: $jsonData"
}
)
$response = Invoke-RestMethod -Uri $azureOpenAIUrl -Headers $headers -Body ($body | ConvertTo-Json) -Method Post
The prompt took a bit of tuning. I wanted something entertaining, but not ruthless. Enough to call out brilliant decisions and unfortunate captain picks, without turning the chat into a post-match inquest.
The Results
What had previously taken close to an hour now took about 30 seconds.
The script pulls the data, crunches the numbers, sends the structured output to Azure OpenAI, and drops the final write-up straight into my clipboard. From there, I can paste it directly into the league chat.
That small bit of automation changed the feel of the league. It made weekly discussion more active, more competitive, and a lot more fun.
Conclusion
This started as a side project for Fantasy Premier League, but the pattern is much broader than football. If you have a repetitive analysis task, there is a good chance you can automate the data gathering and let AI help produce the insights.
That might be sales reporting, cloud operations, service health reviews, or just workplace bragging rights in an FPL league.
The full script is available on GitHub if you want to adapt it for your own setup:
Will it improve your Fantasy Premier League performance? Probably not. But it might make the whole experience a lot more fun.
