football_badges

Create a GitHub-style badge showing the score of a football match.

The badge is based on pybadges.

Docs

Documentation Build Status Docs Check Status

Tests

Linux Test Status Windows Test Status macOS Test Status Coverage

PyPI

PyPI - Package Version PyPI - Supported Python Versions PyPI - Supported Implementations PyPI - Wheel

Activity

GitHub last commit GitHub commits since tagged version Maintenance PyPI - Downloads

QA

CodeFactor Grade Flake8 Status mypy status pre-commit.ci status

Other

License GitHub top language Requirements Status

Installation

python3 -m pip install football_badges --user
python3 -m pip install git+https://github.com/domdfcoding/football_badges@master --user

Example

_images/football_score_demo.svg

150px width 150

320px width 320

500px width 500

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env python

# 3rd party
from bs4 import BeautifulSoup

# this package
from football_badges import football_badge

s = football_badge(
		home_name="BRE",
		away_name="PNE",
		home_colour="red",
		away_colour="green",
		home_score=9,
		away_score=0,
		elapsed_time="92:34",
		extra_time='5',
		)

with open("doc-source/football_score_demo.svg", 'w', encoding="UTF-8") as fp:
	fp.write(BeautifulSoup(s, "lxml-xml").prettify())

API Reference

Creates a GitHub-style badge showing the score of a football match.

Functions:

football_badge(home_name, away_name, …[, …])

Creates a GitHub-style badge showing the score of a football match.

football_badge(home_name, away_name, home_score, away_score, home_colour, away_colour, *, elapsed_time=None, extra_time=None, title='Football Score', measurer=None)[source]

Creates a GitHub-style badge showing the score of a football match.

Parameters
  • home_name (str) – The 2- or 3-letter code representing the home team, to be displayed on the left of the badge.

  • away_name (str) – The 2- or 3-letter code representing the away team, to be displayed on the right of the badge.

  • home_score (int) – The score of the home team.

  • away_score (int) – The score of the away team.

  • home_colour (str) – The background colour for the home team.

  • away_colour (str) – The background colour for the away team.

  • elapsed_time (Optional[str]) – The elapsed time in the match. Default None.

  • extra_time (Union[int, str, None]) – The number of minutes of extra time. Default None.

  • title (str) – The title to set in the SVG file. See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/title. Default 'Football Score'.

  • measurer (Optional[TextMeasurer]) – A text_measurer.TextMeasurer that can be used to measure the width of left_text and right_text. Default None.

See also

https://liaison.reuters.com/tools/sports-team-codes for a list of team codes.

Return type

str

Contributing

football_badges uses tox to automate testing and packaging, and pre-commit to maintain code quality.

Install pre-commit with pip and install the git hook:

python -m pip install pre-commit
pre-commit install

Coding style

yapf-isort is used for code formatting.

It can be run manually via pre-commit:

pre-commit run yapf-isort -a

Or, to run the complete autoformatting suite:

pre-commit run -a

Automated tests

Tests are run with tox and pytest. To run tests for a specific Python version, such as Python 3.6, run:

tox -e py36

To run tests for all Python versions, simply run:

tox

Type Annotations

Type annotations are checked using mypy. Run mypy using tox:

tox -e mypy

Build documentation locally

The documentation is powered by Sphinx. A local copy of the documentation can be built with tox:

tox -e docs

Downloading source code

The football_badges source code is available on GitHub, and can be accessed from the following URL: https://github.com/domdfcoding/football_badges

If you have git installed, you can clone the repository with the following command:

$ git clone https://github.com/domdfcoding/football_badges"
> Cloning into 'football_badges'...
> remote: Enumerating objects: 47, done.
> remote: Counting objects: 100% (47/47), done.
> remote: Compressing objects: 100% (41/41), done.
> remote: Total 173 (delta 16), reused 17 (delta 6), pack-reused 126
> Receiving objects: 100% (173/173), 126.56 KiB | 678.00 KiB/s, done.
> Resolving deltas: 100% (66/66), done.
Alternatively, the code can be downloaded in a ‘zip’ file by clicking:
Clone or download –> Download Zip
Downloading a 'zip' file of the source code.

Downloading a ‘zip’ file of the source code

Building from source

The recommended way to build football_badges is to use tox:

tox -e build

The source and wheel distributions will be in the directory dist.

If you wish, you may also use pep517.build or another PEP 517-compatible build tool.

View the Function Index or browse the Source Code.

Browse the GitHub Repository