From e19e2896a220462394053029722d92f50ec009bf Mon Sep 17 00:00:00 2001 From: Daan Koning Date: Mon, 23 Jan 2023 12:57:23 +0100 Subject: [PATCH] Basic tqdm functionality --- logic.py | 6 ++++++ main.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/logic.py b/logic.py index 9c31ddd..8090687 100644 --- a/logic.py +++ b/logic.py @@ -2,6 +2,11 @@ from typing import Iterable, Generator import time import requests +try: + from tqdm import tqdm +except ImportError: + tqdm = lambda *args, **kwargs: args[0] + BASE_URL = "api.the-odds-api.com/v4" PROTOCOL = "https://" @@ -59,6 +64,7 @@ def get_data(key: str, sport: str, region: str = "eu"): def process_data(matches: Iterable, include_started_matches: bool = True) -> Generator[dict, None, None]: """Extracts all matches that are available and calculates some things about them, such as the time to start and the best available implied odds.""" + matches = tqdm(matches, desc="Checking all matches", leave=False, unit=" matches") for match in matches: start_time = int(match["commence_time"]) if not include_started_matches and start_time < time.time(): diff --git a/main.py b/main.py index df72d00..67165f4 100644 --- a/main.py +++ b/main.py @@ -51,7 +51,7 @@ def main(): data = chain.from_iterable(get_data(key, sport, region=region) for sport in sports) data = filter(lambda x: x != "message", data) results = process_data(data) - arbitrage_opportunities = filter(lambda x: x["total_implied_odds"] < 1-cutoff, results) + arbitrage_opportunities = filter(lambda x: 0 < x["total_implied_odds"] < 1-cutoff, results) if print_unformatted: print(list(arbitrage_opportunities))