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.3.tar.gz (7.3 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.3-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bet_syntax-0.1.3.tar.gz
  • Upload date:
  • Size: 7.3 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.3.tar.gz
Algorithm Hash digest
SHA256 2e4da8b5da76f0b262449d4e89093f16b7671dc939ac815aef827994f764d89c
MD5 9a390205e7f9bbe0e128163cd6846df3
BLAKE2b-256 ee80d2e845c3ebc44e21a56bfd0467919a62b241ca863cf93fd62fc4fffc1a2b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bet_syntax-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.4 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8c3d51e26ab47a7ea01bbad549f1b692f1f67ac4d242f3650d6ad612271028ad
MD5 40dd81149aa5f436bfc2636fbcf482f3
BLAKE2b-256 825a6159951bff2458c817ff4ddc866f34d680ff0e12ec353f225da78ff4e7d0

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