Basic tqdm functionality

This commit is contained in:
Daan Koning
2023-01-23 12:57:23 +01:00
parent c91b0f32b0
commit e19e2896a2
2 changed files with 7 additions and 1 deletions

View File

@@ -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():

View File

@@ -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))