Refactor: main.py is more legible
This commit is contained in:
13
logic.py
13
logic.py
@@ -1,6 +1,7 @@
|
||||
from typing import Iterable, Generator
|
||||
import time
|
||||
import requests
|
||||
from itertools import chain
|
||||
|
||||
try:
|
||||
from tqdm import tqdm
|
||||
@@ -91,4 +92,14 @@ def process_data(matches: Iterable, include_started_matches: bool = True) -> Gen
|
||||
"league": league,
|
||||
"best_outcome_odds": best_odd_per_outcome,
|
||||
"total_implied_odds": total_implied_odds,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def get_arbitrage_opportunities(key: str, region: str, cutoff: float):
|
||||
sports = get_sports(key)
|
||||
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: 0 < x["total_implied_odds"] < 1-cutoff, results)
|
||||
|
||||
return arbitrage_opportunities
|
||||
10
main.py
10
main.py
@@ -2,9 +2,8 @@
|
||||
|
||||
The tool fetches the odds from The Odds API (https://the-odds-api.com/) and compares the odds at different
|
||||
bookmakers to each other in order to determine whether there are profitable and risk-free bets available."""
|
||||
from logic import *
|
||||
from logic import get_arbitrage_opportunities
|
||||
import os
|
||||
from itertools import chain
|
||||
import argparse
|
||||
from dotenv import load_dotenv
|
||||
from rich import print
|
||||
@@ -46,12 +45,7 @@ def main():
|
||||
print_unformatted = args.unformatted
|
||||
cutoff = args.cutoff/100
|
||||
|
||||
# logic
|
||||
sports = get_sports(key)
|
||||
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: 0 < x["total_implied_odds"] < 1-cutoff, results)
|
||||
arbitrage_opportunities = get_arbitrage_opportunities(key, region, cutoff)
|
||||
|
||||
if print_unformatted:
|
||||
print(list(arbitrage_opportunities))
|
||||
|
||||
Reference in New Issue
Block a user