Added pretty printing, reintroduced rich dependancy

This commit is contained in:
Daan Koning
2022-11-23 21:48:38 +01:00
parent 3adbe61bfa
commit ff1dd5e71b
3 changed files with 27 additions and 10 deletions

View File

@@ -17,7 +17,7 @@ Next, ensure you have an API key from The Odds API and simply run:
python main.py --key <YOUR_API_KEY> python main.py --key <YOUR_API_KEY>
## Usage ## Usage
The tool offers three optional command line arguments. The tool offers four optional command line arguments.
### API key ### API key
In order to set the API key to use either the `-k` or `--key` arguments. If neither of these are used the script will read the value of `$API_KEY`. `.env` files are also supported and automatically loaded. In order to set the API key to use either the `-k` or `--key` arguments. If neither of these are used the script will read the value of `$API_KEY`. `.env` files are also supported and automatically loaded.
@@ -25,5 +25,8 @@ In order to set the API key to use either the `-k` or `--key` arguments. If neit
### Region ### Region
Different parts of the world have different bookmakers. To reflect this the `-r` or `--region` arguments allow you to set the region in which to search. Accepts the values `"eu"`,`"us"`, `"uk"`, and `"au"`. Different parts of the world have different bookmakers. To reflect this the `-r` or `--region` arguments allow you to set the region in which to search. Accepts the values `"eu"`,`"us"`, `"uk"`, and `"au"`.
### Unformatted
Using the `-u` or `--unformatted` will remove the pretty printing and simply dump the json which contains the arbs to the console directly. Use this if you intend to extend upon the script in some way, for regular usage the formatted print is significantly better.
### Help ### Help
The `-h` or `--help` flags will show a short help message with documentation. The `-h` or `--help` flags will show a short help message with documentation.

29
main.py
View File

@@ -1,12 +1,9 @@
from logic import * from logic import *
import os import os, sys
from itertools import chain from itertools import chain
import argparse import argparse
from dotenv import load_dotenv from dotenv import load_dotenv
try: from rich import print
from rich import print
except ImportError:
pass
def main(): def main():
@@ -30,20 +27,36 @@ def main():
default="eu", default="eu",
help="The region in which to look for arbitrage opportunities." help="The region in which to look for arbitrage opportunities."
) )
parser.add_argument(
"-u", "--unformatted",
action="store_true",
help="If set, turn output into the json dump from the opportunities."
)
args = parser.parse_args() args = parser.parse_args()
key = args.key key = args.key
region = args.region region = args.region
print_unformatted = args.unformatted
# logic # logic
sports = get_sports(key) sports = get_sports(key)
data = chain.from_iterable(get_data(key, sport, region=region) for sport in sports) data = chain.from_iterable(get_data(key, sport, region=region) for sport in sports)
data = filter(lambda x: x != "message", data) data = filter(lambda x: x != "message", data)
results = process_data(data) results = process_data(data)
arbitrage_opportunities = filter(lambda x: x["total_implied_odds"] < 1, results) arbitrage_opportunities = filter(lambda x: x["total_implied_odds"] < 1, results)
for i in arbitrage_opportunities:
print(i) if print_unformatted:
for arb in arbitrage_opportunities:
print(arb)
else:
arbitrage_opportunities = list(arbitrage_opportunities)
print(f"{len(arbitrage_opportunities)} arbitrage opportunities found {':money-mouth_face:' if len(arbitrage_opportunities) > 0 else ':man_shrugging:'}")
for arb in arbitrage_opportunities:
print(f"\t[italic]{arb['match_name']} in {arb['league']} [/italic]")
print(f"\t\tTotal implied odds: {arb['total_implied_odds']} with these odds:")
for key, value in arb['best_outcome_odds'].items():
print(f"\t\t[bold red]{key}[/bold red] with [green]{value[0]}[/green] for {value[1]}")
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -1,2 +1,3 @@
requests~=2.28.1 requests~=2.28.1
python-dotenv~=0.21.0 python-dotenv~=0.21.0
rich~=12.6.0