mirror of
https://github.com/onyx-and-iris/lottery-tui.git
synced 2026-04-20 02:13:31 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a986348168 | |||
| bccf1b1ad2 | |||
| 3ecfb84a87 | |||
| 039487cfc5 | |||
| 84fcbd326a | |||
| 47ced52722 |
@@ -1,6 +1,6 @@
|
|||||||
# Lottery TUI
|
# Lottery TUI
|
||||||
|
|
||||||
[](https://pdm.fming.dev)
|
[](https://pdm-project.org)
|
||||||
[](https://github.com/astral-sh/ruff)
|
[](https://github.com/astral-sh/ruff)
|
||||||
[](https://pypi.org/project/lottery-tui)
|
[](https://pypi.org/project/lottery-tui)
|
||||||
[](https://pypi.org/project/lottery-tui)
|
[](https://pypi.org/project/lottery-tui)
|
||||||
|
|||||||
BIN
img/tui.png
BIN
img/tui.png
Binary file not shown.
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 23 KiB |
@@ -1,12 +1,21 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "lottery-tui"
|
name = "lottery-tui"
|
||||||
version = "0.2.0"
|
version = "0.2.3"
|
||||||
description = "A terminal user interface for lottery games."
|
description = "A terminal user interface for lottery games."
|
||||||
authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }]
|
authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }]
|
||||||
dependencies = ["textual>=8.0.0"]
|
dependencies = ["textual>=8.0.0"]
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = { text = "MIT" }
|
license = { text = "MIT" }
|
||||||
|
classifiers = [
|
||||||
|
"Development Status :: 4 - Beta",
|
||||||
|
"Programming Language :: Python",
|
||||||
|
"Programming Language :: Python :: 3.10",
|
||||||
|
"Programming Language :: Python :: 3.11",
|
||||||
|
"Programming Language :: Python :: 3.12",
|
||||||
|
"Programming Language :: Python :: Implementation :: CPython",
|
||||||
|
"Programming Language :: Python :: Implementation :: PyPy",
|
||||||
|
]
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
lottery-tui = "lottery_tui.tui:main"
|
lottery-tui = "lottery_tui.tui:main"
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class Result(NamedTuple):
|
|||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
"""Return a string representation of the lottery result."""
|
"""Return a string representation of the lottery result."""
|
||||||
out = f'Numbers: {", ".join(str(n) for n in self.numbers)}'
|
out = f'Numbers: {", ".join(str(n) for n in sorted(self.numbers))}'
|
||||||
if self.bonus:
|
if self.bonus:
|
||||||
match self.kind:
|
match self.kind:
|
||||||
case 'EuroMillions':
|
case 'EuroMillions':
|
||||||
@@ -23,7 +23,7 @@ class Result(NamedTuple):
|
|||||||
bonus_name = 'Thunderball'
|
bonus_name = 'Thunderball'
|
||||||
case _:
|
case _:
|
||||||
bonus_name = 'Bonus Numbers'
|
bonus_name = 'Bonus Numbers'
|
||||||
out += f'\n{bonus_name}: {", ".join(str(n) for n in self.bonus)}'
|
out += f'\n{bonus_name}: {", ".join(str(n) for n in sorted(self.bonus))}'
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ class Lottery(ABC):
|
|||||||
"""An abstract base class for different types of lotteries."""
|
"""An abstract base class for different types of lotteries."""
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def draw(self):
|
def draw(self) -> Result:
|
||||||
"""Perform a lottery draw."""
|
"""Perform a lottery draw."""
|
||||||
|
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ class UKlotto(Lottery):
|
|||||||
|
|
||||||
POSSIBLE_NUMBERS = range(1, 60)
|
POSSIBLE_NUMBERS = range(1, 60)
|
||||||
|
|
||||||
def draw(self):
|
def draw(self) -> Result:
|
||||||
"""Perform a UK Lotto draw."""
|
"""Perform a UK Lotto draw."""
|
||||||
result = random.sample(UKlotto.POSSIBLE_NUMBERS, 6)
|
result = random.sample(UKlotto.POSSIBLE_NUMBERS, 6)
|
||||||
return Result(kind='UK Lotto', numbers=result, bonus=None)
|
return Result(kind='UK Lotto', numbers=result, bonus=None)
|
||||||
@@ -71,7 +71,7 @@ class EuroMillions(Lottery):
|
|||||||
POSSIBLE_NUMBERS = range(1, 51)
|
POSSIBLE_NUMBERS = range(1, 51)
|
||||||
POSSIBLE_BONUS_NUMBERS = range(1, 13)
|
POSSIBLE_BONUS_NUMBERS = range(1, 13)
|
||||||
|
|
||||||
def draw(self):
|
def draw(self) -> Result:
|
||||||
"""Perform a EuroMillions draw."""
|
"""Perform a EuroMillions draw."""
|
||||||
numbers = random.sample(EuroMillions.POSSIBLE_NUMBERS, 5)
|
numbers = random.sample(EuroMillions.POSSIBLE_NUMBERS, 5)
|
||||||
bonus = random.sample(EuroMillions.POSSIBLE_BONUS_NUMBERS, 2)
|
bonus = random.sample(EuroMillions.POSSIBLE_BONUS_NUMBERS, 2)
|
||||||
@@ -88,7 +88,7 @@ class SetForLife(Lottery):
|
|||||||
|
|
||||||
POSSIBLE_NUMBERS = range(1, 40)
|
POSSIBLE_NUMBERS = range(1, 40)
|
||||||
|
|
||||||
def draw(self):
|
def draw(self) -> Result:
|
||||||
"""Perform a Set For Life draw."""
|
"""Perform a Set For Life draw."""
|
||||||
numbers = random.sample(SetForLife.POSSIBLE_NUMBERS, 5)
|
numbers = random.sample(SetForLife.POSSIBLE_NUMBERS, 5)
|
||||||
life_ball = [random.randint(1, 10)]
|
life_ball = [random.randint(1, 10)]
|
||||||
@@ -103,9 +103,9 @@ class Thunderball(Lottery):
|
|||||||
and 1 "Thunderball" number from a separate pool of 1 to 14, also without replacement.
|
and 1 "Thunderball" number from a separate pool of 1 to 14, also without replacement.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
POSSIBLE_NUMBERS = range(1, 40) # Thunderball numbers range from 1 to 39
|
POSSIBLE_NUMBERS = range(1, 40)
|
||||||
|
|
||||||
def draw(self):
|
def draw(self) -> Result:
|
||||||
"""Perform a Thunderball draw."""
|
"""Perform a Thunderball draw."""
|
||||||
numbers = random.sample(Thunderball.POSSIBLE_NUMBERS, 5)
|
numbers = random.sample(Thunderball.POSSIBLE_NUMBERS, 5)
|
||||||
thunderball = [random.randint(1, 14)]
|
thunderball = [random.randint(1, 14)]
|
||||||
|
|||||||
@@ -37,11 +37,17 @@ class LotteryTUI(App):
|
|||||||
def on_button_pressed(self, event):
|
def on_button_pressed(self, event):
|
||||||
"""Handle button press events."""
|
"""Handle button press events."""
|
||||||
if event.button.id == 'draw-button':
|
if event.button.id == 'draw-button':
|
||||||
|
if self.query_one('#lottery-select').is_blank():
|
||||||
|
self.query_one('#result-label').update(
|
||||||
|
'Please select a lottery before drawing.'
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
selected_lottery = self.query_one('#lottery-select').value
|
selected_lottery = self.query_one('#lottery-select').value
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lottery_obj = request_lottery_obj(selected_lottery)
|
lottery_obj = request_lottery_obj(selected_lottery)
|
||||||
result = lottery_obj.draw()
|
result = lottery_obj.draw()
|
||||||
self.query_one('#result-label').update(f'Result: {result}')
|
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
self.query_one('#result-label').update(str(e))
|
self.query_one('#result-label').update(str(e))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user