Skip to main content

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
  • x3 means multiplier 3
  • x1.5 means multiplier 1.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:1 or 2: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

bet_syntax-0.1.2.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bet_syntax-0.1.2-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file bet_syntax-0.1.2.tar.gz.

File metadata

  • Download URL: bet_syntax-0.1.2.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

Hashes for bet_syntax-0.1.2.tar.gz
Algorithm Hash digest
SHA256 904f86d3ef859a666403df6ec4d854679372d4a3d37af35bcd105f6fd5fb5531
MD5 f1639d4ab1060c7bb091841134643d0f
BLAKE2b-256 6a59a69648216a1cc195a5bee11cdb89b908eadb4b240e28310e57f282b31789

See more details on using hashes here.

File details

Details for the file bet_syntax-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: bet_syntax-0.1.2-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

Hashes for bet_syntax-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c8298ea299da1a451c9404e8c999c55bbe11c26c9a407bc33fe02ed92789265e
MD5 a1a1174273c0a22d0fae019d2aa50849
BLAKE2b-256 2170c3db683829020c3fbe223bd4db1490af46802335146102fd69968181e06b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page