Last active
August 19, 2025 00:45
-
-
Save matt-dray/c97603f294fb80736b669141191d827b to your computer and use it in GitHub Desktop.
Get the identity and date of the next bank holiday in England and Wales (with bunting if appropriate) from the command line with a standalone Python-script executable run by uv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env -S uv run | |
| # /// script | |
| # requires-python = ">=3.12" | |
| # dependencies = [ | |
| # "datetime", | |
| # "httpx", | |
| # ] | |
| # /// | |
| # Blogpost here: | |
| # https://www.rostrum.blog/posts/2025-08-11-uv-standalone/ | |
| # With regards to: | |
| # https://mathspp.com/blog/til/standalone-executable-python-scripts-with-uv | |
| # https://simonwillison.net/2024/Aug/21/usrbinenv-uv-run/ | |
| # Install uv, download this script, then: | |
| # chmod +x bank.py | |
| # mv bank.py ~/.local/bin | |
| # bank.py | |
| import httpx | |
| from datetime import date | |
| # Fetch bank holidays | |
| resp = httpx.get("https://www.gov.uk/bank-holidays.json") | |
| events = resp.json()["england-and-wales"]["events"] | |
| for event in events: | |
| event["date"] = date.fromisoformat(event["date"]) | |
| # Find next holiday | |
| today = date.today() | |
| future = [event for event in events if event["date"] >= today] | |
| next = future[0] | |
| # Print message | |
| is_today = next["date"] == today | |
| needs_bunting = next["bunting"] | |
| if is_today: | |
| when = "today!" | |
| else: | |
| when = f"on {next['date'].strftime('%d %B %Y')}" | |
| str_out = f"{next['title']} is {when}" | |
| if needs_bunting: | |
| str_out = str_out + " ▼▽▼▽▼▽" | |
| print(str_out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment