Unify id logic in cli, remove defaults from data models
This commit is contained in:
@@ -144,8 +144,8 @@ def load_config(path: str) -> Config | None:
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(prog="beaky")
|
||||
parser.add_argument("--config", help="Path to config file.", default="config/application.yml")
|
||||
parser.add_argument("--id", type=int, help="Resolve a single ticket by id (only used with resolve mode).")
|
||||
parser.add_argument("mode", choices=["screenshotter", "parser", "class", "resolve", "compare"], help="Mode of operation.")
|
||||
parser.add_argument("--id", type=int, help="Select a single ticket by id.")
|
||||
parser.add_argument("mode", choices=["screen", "parse", "class", "resolve", "compare"], help="Mode of operation.")
|
||||
|
||||
args = parser.parse_args()
|
||||
config = load_config(args.config)
|
||||
@@ -156,23 +156,33 @@ def main() -> None:
|
||||
data = Links(config)
|
||||
data.ret_links()
|
||||
link_amount = len(data.links)
|
||||
print(f"We found {link_amount} links")
|
||||
if link_amount == 0:
|
||||
print("ERROR, no links found")
|
||||
return
|
||||
print(f"We found {link_amount} links")
|
||||
|
||||
if args.mode == "screenshotter":
|
||||
# link selection
|
||||
if args.id is not None:
|
||||
selected_links = [l for l in data.links if l.id == args.id] if args.id is not None else data.links
|
||||
if not selected_links:
|
||||
print(f"ERROR: ticket id {args.id} not found")
|
||||
return
|
||||
print(f"Selected link: {args.id}")
|
||||
else:
|
||||
selected_links = data.links
|
||||
|
||||
if args.mode == "screen":
|
||||
screenshotter = Screenshotter(config)
|
||||
screenshotter.capture_tickets(data.links)
|
||||
screenshotter.capture_tickets(selected_links)
|
||||
|
||||
if args.mode == "parser":
|
||||
for link in data.links:
|
||||
if args.mode == "parse":
|
||||
for link in selected_links:
|
||||
print(link)
|
||||
|
||||
if args.mode == "class":
|
||||
classifier = LinkClassifier()
|
||||
results = []
|
||||
for link in data.links:
|
||||
for link in selected_links:
|
||||
results.append(classifier.classify(link))
|
||||
ticket = results[-1]
|
||||
print(f"\n=== Link {ticket.id} ({len(ticket.bets)} bets) ===")
|
||||
@@ -183,11 +193,7 @@ def main() -> None:
|
||||
|
||||
if args.mode == "compare":
|
||||
linkclassifier = LinkClassifier()
|
||||
links = [l for l in data.links if l.id == args.id] if args.id is not None else data.links
|
||||
if args.id is not None and not links:
|
||||
print(f"ERROR: ticket id {args.id} not found")
|
||||
return
|
||||
for link in links:
|
||||
for link in selected_links:
|
||||
link_ticket = linkclassifier.classify(link)
|
||||
img_ticket = img_classify([f"./data/screenshots/{link.id}.png"], ticket_id=link.id)
|
||||
_print_compare(link_ticket, img_ticket)
|
||||
@@ -195,11 +201,8 @@ def main() -> None:
|
||||
if args.mode == "resolve":
|
||||
classifier = LinkClassifier()
|
||||
resolver = TicketResolver(config.resolver)
|
||||
links = [l for l in data.links if l.id == args.id] if args.id is not None else data.links
|
||||
if args.id is not None and not links:
|
||||
print(f"ERROR: ticket id {args.id} not found")
|
||||
return
|
||||
for link in links:
|
||||
|
||||
for link in selected_links:
|
||||
print(f"\n=== Classifying ticket {link.id} ===")
|
||||
ticket = classifier.classify(link)
|
||||
for bet in ticket.bets:
|
||||
|
||||
@@ -50,7 +50,7 @@ class Bet(ABC):
|
||||
class WinDrawLose(Bet):
|
||||
"""Výsledek zápasu 1X2"""
|
||||
|
||||
betType: Literal["X", "0", "1", "2"] = "0"
|
||||
betType: Literal["X", "0", "1", "2"]
|
||||
|
||||
def resolve(self, match: MatchInfo) -> BetOutcome:
|
||||
home, away = match.goals_home, match.goals_away
|
||||
@@ -73,7 +73,7 @@ class Advance(Bet):
|
||||
class WinDrawLoseDouble(Bet):
|
||||
"""Výsledek zápasu - double"""
|
||||
|
||||
betType: Literal["01", "12", "02"] = "01"
|
||||
betType: Literal["01", "12", "02"]
|
||||
|
||||
def resolve(self, match: MatchInfo) -> BetOutcome:
|
||||
home, away = match.goals_home, match.goals_away
|
||||
@@ -85,7 +85,7 @@ class WinDrawLoseDouble(Bet):
|
||||
class WinLose(Bet):
|
||||
"""Výsledek zápasu bez remízy"""
|
||||
|
||||
betType: Literal["1", "2"] = "1"
|
||||
betType: Literal["1", "2"]
|
||||
|
||||
def resolve(self, match: MatchInfo) -> BetOutcome:
|
||||
home, away = match.goals_home, match.goals_away
|
||||
@@ -105,8 +105,8 @@ class BothTeamScored(Bet):
|
||||
class GoalAmount(Bet):
|
||||
"""Počet gólů v zápasu — over/under total goals"""
|
||||
|
||||
line: float = 0.0 # goal line, e.g. 2.5
|
||||
over: bool = True # True = more than line, False = less than line
|
||||
line: float
|
||||
over: bool # True = more than line, False = less than line
|
||||
|
||||
def resolve(self, match: MatchInfo) -> BetOutcome:
|
||||
total = match.goals_home + match.goals_away
|
||||
@@ -120,8 +120,8 @@ class GoalAmount(Bet):
|
||||
class GoalHandicap(Bet):
|
||||
"""Goal handicap for a specific team — add handicap_amount to team's score, team wins = you win"""
|
||||
|
||||
team_bet: Literal["1", "2"] = "1" # which team the handicap is applied to
|
||||
handicap_amount: float = 0.0 # e.g. +1.5 or -0.5
|
||||
team_bet: Literal["1", "2"] # which team the handicap is applied to
|
||||
handicap_amount: float # e.g. +1.5 or -0.5
|
||||
|
||||
def resolve(self, match: MatchInfo) -> BetOutcome:
|
||||
home = match.goals_home + (self.handicap_amount if self.team_bet == "1" else 0.0)
|
||||
|
||||
Reference in New Issue
Block a user