A parser for betting rules syntax
Project description
bet-syntax
A parser for betting rules syntax. Parses structured betting rule definitions into JSON format.
Installation
pip install bet-syntax
Usage
from bet_syntax import parse_input
rules_text = """
["Group Stage - 3", "Round of 32"] | * :: fh<sh x1
"Round of 16" | * :: fh<sh x1.5
"""
result = parse_input(rules_text)
print(result)
Matching Games Against Rules
You can match a game against single or multiple rules to check if it satisfies any betting condition.
Single Rule
Use match_rule_to_game to check if a game matches one rule:
from bet_syntax import match_rule_to_game
game = {
"roundName": "Quarter-finals",
"gameName": "France - Morocco",
"homeFTResult": 3,
"awayFTResult": 1,
}
rule = '"Quarter-finals" | "France - Morocco" :: 3:1'
if match_rule_to_game(rule, game):
print("Game matches the rule!")
Multiple Rules
Use match_rules_to_game to check if a game matches ANY rule from a multiline string (OR logic):
from bet_syntax import match_rules_to_game
game = {
"roundName": "Quarter-finals",
"gameName": "France - Morocco",
"homeFTResult": 3,
"awayFTResult": 1,
}
rules_text = """
"Quarter-finals" | "France - Morocco" :: 2:1 | 3:1 x3
"Quarter-finals" | "Spain - Belgium" :: 2:1 | 3:1 x3
"""
if match_rules_to_game(rules_text, game):
print("Game matches at least one rule!")
The function returns True if the game satisfies any of the rules, False otherwise.
Bet Syntax
Each rule has this shape:
round selector | game selector :: bet syntax x multiplier
Selectors
The part before :: chooses which matches a rule applies to.
- Round selector: matches
roundName - Game selector: matches
gameName
Examples:
"Quarter-finals" :: 3:1
"Quarter-finals" | "France - Morocco" :: 3:1
"Round of 16" | * :: fh<sh
- Use a quoted value to match one exact round or game name.
- Use a list like
["Group Stage - 3", "Round of 32"]to match several round names. - Use
*to match any game name. - If you provide only one selector, it is treated as the round selector and the game selector becomes
*.
Bets
The part after :: describes what result should match.
- Exact score:
3:1 - Multiple score alternatives:
3:1 | 2:1 - Half comparison:
fh<sh,fh=sh,fh>sh - Total goals:
total=4
If a bet has multiple alternatives, | means OR. For example, 3:1 | 2:1 matches either final score.
Multiplier
You can add a multiplier at the end with x:
"Quarter-finals" | "France - Morocco" :: 3:1 x3
"Round of 16" :: fh<sh x1.5
x3means multiplier3x1.5means multiplier1.5- If no multiplier is provided, the default is
1
Example
"Quarter-finals" | "France - Morocco" :: 3:1 | 2:1 x3
This rule means:
- apply only to the quarter-finals match between France and Morocco
- match either score
3:1or2:1 - apply multiplier
3
Or from the command line:
echo 'your rules here' | bet-syntax
Development
Run tests:
make test
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bet_syntax-0.1.1.tar.gz.
File metadata
- Download URL: bet_syntax-0.1.1.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f4bab86c1b5f367c79ef195e1308af5b2828e462e5630f3c48087b976b41121
|
|
| MD5 |
7cf66e00cfa5ab3b4f23963ca58fa78f
|
|
| BLAKE2b-256 |
8c643ea23c49e4001ed26bd79645789bfb4b65691c6a03fbb94b838f9fb98571
|
File details
Details for the file bet_syntax-0.1.1-py3-none-any.whl.
File metadata
- Download URL: bet_syntax-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7820702835707def4bf135c852513b7c2e488c0d7f440ac035578576f0c29e1
|
|
| MD5 |
7342c300ec1b18f9dc7865ed84f48490
|
|
| BLAKE2b-256 |
f651fb3b52d200281acf1a481247a065cc7fac96069bfea9fe8d31f57683cbcf
|