How leojoker/lanusstats works
Project Type & Purpose
• LanusStats is an open-source Python library/SDK for scraping soccer statistics from multiple external websites (FBref, FotMob, SofaScore, 365Scores, Transfermarkt) and generating ready-to-use visualizations.
High-Level Components
• FBref
• FotMob
• SofaScore
• 365Scores
• Transfermarkt
1. config.py
• Stores constants, URL templates, headers, default parameters
2. exceptions.py
• Defines custom exception classes for error handling
3. functions.py
• Shared utility functions: HTTP request wrappers, HTML parsing helpers, DataFrame cleaning
4. datafactory.py
• Implements the Factory Pattern: dispatches user calls to the correct scraper class based on the chosen “page”
5. Scraper Modules (one class per file)
• fbref.py → class Fbref
• fotmob.py → class FotMob
• sofascore.py → class SofaScore
• threesixfivescores.py → class ThreeSixFiveScores
• transfermarkt.py → class Transfermarkt
6. visualizations.py
• Prebuilt plotting functions that invoke scraper methods, then render via Matplotlib/MPLSoccer
7. setup.py
• Installation metadata and entry point definitions
C. CI/CD Pipeline
• .github/workflows/publish-package.yml
• Trigger: Git tag push → build/test → publish to PyPI
Relationships & Data Flow
1. User Script / Notebook
→ Instantiates one of the LanusStats classes or calls a generic factory function
2. datafactory.py (if used)
→ Returns an instance of the appropriate scraper class
3. Scraper Class (e.g., Fbref)
→ Calls functions.py utilities to build and send HTTP requests to its external website
→ Parses HTML/JSON response, handles errors via exceptions.py
→ Constructs and returns a pandas DataFrame (or saves CSV/Excel if flagged)
4. visualizations.py (when invoked)
→ Calls scraper methods under the hood
→ Takes returned DataFrame and generates plots (heatmaps, shotmaps, hexbins, etc.)
5. CI/CD
→ On tag push, GitHub Actions runs tests, builds package, and publishes to PyPI
Architectural Patterns & Principles
• Factory Pattern: datafactory.py dynamically selects the right scraper class
• Single Responsibility:
• Each scraper module focuses on one data source
• Shared logic centralized in functions.py, config.py, exceptions.py
• Visualization logic isolated in visualizations.py
• Extensibility: To add a new site, you add a scraper module + register it in datafactory.py
• Loose Coupling: User code and visualization code depend only on the public scraper interfaces