lottery-random is a true random lottery ticket generator with the help of the random.org API. It emails you true random numbers for the configured lottery ticket packs via Azure Communication Services in the following format:
Lottery numbers for John Smith
Lottery numbers for John Smith
Lottery 5: [2, 5, 26, 43, 87], [3, 27, 42, 54, 87]
Lottery 6: [4, 7, 18, 32, 38, 39], [1, 2, 13, 27, 37, 40], [9, 17, 23, 30, 41, 43], [4, 8, 9, 12, 28, 37]
EuroJackpot: [15, 20, 23, 28, 44 | 1, 8], [2, 3, 24, 39, 41 | 2, 8], [3, 4, 8, 9, 11 | 5, 9]
Timestamp: 2019/05/09 03:25:32 (UTC)
This email was sent you by Jane Smith (jane@smith.com) using https://github.com/luczsoma/lottery-random.
- Python >=3
- An API key for the random.org API*
- An Azure Communication Services instance with an endpoint and an API key
*Please note that you are not allowed to use an API key with neither Developer nor Non-Profit API key licenses: visit https://api.random.org/pricing for details.
Clone the repository:
git clone https://github.com/luczsoma/lottery-random.gitCreate a virtual environment and activate it:
python -m venv venv
. ./venv/bin/activateInstall all dependencies:
pip install -r requirements.txtClone the example configuration file into your config file:
cp config.example.json config.jsonFill the config file with your desired configuration, and you are ready to go.
Run the following command to send randomly filled lottery tickets to the given email addresses:
python src/lottery-random.pyOr use lottery-random from Python code:
from lottery-random import LotteryRandom
LotteryRandom().run()There are quite a few methods to run lottery-random periodically. E.g., if you have an always-on server anywhere on the internet you can add an entry to your user's crontab file. Enter:
crontab -eThen enter the following:
0 0 * * 0 python lottery-random.py
This will run lottery-random every Sunday at midnight (according to your server's time zone).
You can see the JSON schema of the config.json file defined in config.schema.json. Your config.json file must comply with the provided schema.
Provide your random.org API key in the random_org_api_key field:
{
// …
"random_org_api_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
// …
}Please note that you are not allowed to use an API key with neither Developer nor Non-Profit API key licenses: visit https://api.random.org/pricing for details.
Provide your Azure Communication Services endpoint and API key in the azure_email_endpoint and azure_email_key fields, respectively:
{
// …
"azure_email_endpoint": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"azure_email_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
// …
}Provide the email address and name configured in Azure Communication Services in the sender_email and sender_name fields, respectively. Please note that these values will be visible in the email in the following form: "This email was sent you by {sender_name} ({sender_email}) using https://github.com/luczsoma/lottery-random.".
{
// …
"sender_email": "yourserver@yourdomain.com",
"sender_name": "Your Name"
// …
}A lottery game definition is the description of a particular lottery game: it defines how a valid ticket looks like.
E.g., a EuroJackpot ticket consists of two sets of numbers:
- 5 numbers from the [1–50] interval,
- 2 numbers from the [1–12] interval.
This can be configured as follows:
{
// …
"games": [
{
"name": "EuroJackpot",
"fields": [
{
"n": 5,
"min": 1,
"max": 50
},
{
"n": 2,
"min": 1,
"max": 12
}
]
}
]
// …
}A lottery ticket pack is a set of played lottery tickets sent to one or more email addresses. E.g., if you play one ticket of EuroJackpot and one ticket of Lottery 5, and your friend plays one ticket of Lottery 5 and two tickets of Lottery 6 each week, you define two separate lottery ticket packs, which will be sent to you and your friend separately. You can also configure permanent tickets to be played regularly. Permanent tickets must conform to the game definition, and cannot contain duplicate numbers.
Lottery ticket packs can be configured as follows:
{
// …
"ticket_packs": [
{
"name": "Your Sunday pack"
"recipients": [
{
"email": "yourname@yourdomain.com",
"name": "Your Name"
}
],
"elements": [
{
"game": "Lottery 5",
"number_of_random_tickets": 1,
"permanent_tickets": [[[3, 27, 42, 54, 87]]]
},
{
"game": "Lottery 6",
"number_of_random_tickets": 2,
"permanent_tickets": [
[[9, 17, 23, 30, 41, 43]],
[[4, 8, 9, 12, 28, 37]]
]
},
{
"game": "EuroJackpot",
"number_of_random_tickets": 1,
"permanent_tickets": [
[
[2, 5, 24, 39, 41],
[2, 8]
],
[
[3, 4, 8, 9, 11],
[5, 9]
]
]
}
]
},
{
"name": "Your Wednesday pack",
"recipients": [
{
"email": "yourname@yourdomain.com",
"name": "Your Name"
}
],
"elements": [
{
"game": "EuroJackpot",
"number_of_random_tickets": 1,
"permanent_tickets": [
[
[2, 5, 24, 39, 41],
[2, 8]
],
[
[3, 4, 8, 9, 11],
[5, 9]
]
]
}
]
},
{
"name": "Your friend’s pack",
"recipients": [
{
"email": "yourfriendsname@yourfriendsdomain.com",
"name": "Your Friend’s Name"
}
],
"elements": [
{
"game": "Lottery 5",
"number_of_random_tickets": 2,
"permanent_tickets": []
},
{
"game": "Lottery 6",
"number_of_random_tickets": 1,
"permanent_tickets": []
}
]
}
]
// …
}You can send the same lottery ticket pack to multiple recipients with setting the configuration as follows. Please note that the name attribute of a recipient will be visible in the email in the following form: "True random lottery numbers for {name}".
{
// …
"ticket_packs": [
{
"name": "Your Sunday pack",
"recipients": [
{
"email": "yourname@yourdomain.com",
"name": "Your Name"
},
{
"email": "yourfriendsname@yourfriendsdomain.com",
"name": "Your Friend’s Name"
}
],
"elements": [
{
"game": "Lottery 5",
"number_of_random_tickets": 1,
"permanent_tickets": [[[3, 27, 42, 54, 87]]]
},
{
"game": "Lottery 6",
"number_of_random_tickets": 2,
"permanent_tickets": [
[[9, 17, 23, 30, 41, 43]],
[[4, 8, 9, 12, 28, 37]]
]
},
{
"game": "EuroJackpot",
"number_of_random_tickets": 1,
"permanent_tickets": [
[
[2, 5, 24, 39, 41],
[2, 8]
],
[
[3, 4, 8, 9, 11],
[5, 9]
]
]
}
]
}
]
// …
}It is possible to filter lottery ticket packs by name. This is useful for playing lotteries having drawings at a different time (or multiple drawings within a week). You can configure separate lottery ticket packs for each combination, then filter at the invocation.
Filter values need to have corresponding lottery ticket packs defined in config.json, otherwise a RuntimeError is raised. No filtering results in sending all configured lottery ticket packs.
On the command line:
# run on Sunday
python src/lottery-random.py -f/--lottery-ticket-pack-filter "Your Sunday pack" "Your friend's pack"
# run on Wednesday
python src/lottery-random.py -f/--lottery-ticket-pack-filter "Your Wednesday pack"No filtering can be achieved by omitting the -f/--lottery-ticket-pack-filter argument. Specifying -f/--lottery-ticket-pack-filter with no value is not allowed.
If using lottery-random from Python code, filtering can be done by passing a set to the run method:
from lottery-random import LotteryRandom
# run on Sunday
LotteryRandom().run(lottery_ticket_pack_filter={"Your Sunday pack", "Your friend's pack"})
# run on Wednesday
LotteryRandom().run(lottery_ticket_pack_filter={"Your Wednesday pack"})No filtering can be achieved by passing None or not passing an argument to run. Passing an empty set to run is not allowed.