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.0.tar.gz (6.5 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.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bet_syntax-0.1.0.tar.gz
  • Upload date:
  • Size: 6.5 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.0.tar.gz
Algorithm Hash digest
SHA256 68ace35028fda53efb1c588c6e5a6861cffad1a79b0a398d2a48510acbd61088
MD5 d6192b66a9b90986274cf47bf8f0274a
BLAKE2b-256 1d514cf47d727b5c5753a809be8437b70a9195fb5085341c0642dbcba50d7c04

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bet_syntax-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4569c9ea3b198e948fe37a292c87504a4ffcf14245f70f2adae9ce6c5b0ac629
MD5 22ba908978f6fdf8bff107a72c922c92
BLAKE2b-256 2cf5deaee97414cf2fd2bab456e522f22ad53aeaf4a14cff27bdcf63d3f9d4e0

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