Skip to content

Instantly share code, notes, and snippets.

@maduranma
Created December 22, 2022 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maduranma/685e0974d2ded63c5bc66473079f6433 to your computer and use it in GitHub Desktop.
Save maduranma/685e0974d2ded63c5bc66473079f6433 to your computer and use it in GitHub Desktop.
Spanish Christmas Lottery "Lotería de Navidad 2022" - PHP auto-checker
<?php
/*
Spanish Christmas Lottery 2022 auto-checker in PHP
--------------------------------------------------
Fill your coupons below, 20€ is one ticket, insert the quantity you play of each number in euros
Example: 20€ is one ticket, 10€ half a ticket (if you play with someone) or 40€ two tickets.
You can also repeat the same number for two different people.
It updates once every minute.
Good luck!
Author: Martín Durán <mduran@nvan.es>
*/
$coupons = [
['number' => '11111', 'quantity' => 20, 'person' => 'YOUR NAME'],
['number' => '22222', 'quantity' => 20, 'person' => 'YOUR NAME'],
// Add as many entries as you want
];
function out($prestring, $poststring) {
echo str_pad($prestring, 15, ' '), $poststring;
}
while(true)
{
$cache = [];
foreach($coupons as $coupon)
{
if(!isset($cache[$coupon['number']]))
sleep(1);
$response = $cache[$coupon['number']] ??= json_decode(explode('=', file_get_contents('https://api.elpais.com/ws/LoteriaNavidadPremiados?n=' . $coupon['number']), 2)[1], true);
if($response['premio'] > 0)
{
echo out($coupon['person'] . ':', '[' . $coupon['number'] . ' - ' . $coupon['quantity'] . 'EUR] DING DING DING -> EL PREMIO SON: ' . number_format($response['premio'] / 20 * $coupon['quantity'], 0, '', '.') . ' EUROS!!!');
}
else
{
echo out($coupon['person'] . ':', '[' . $coupon['number'] . ' - ' . $coupon['quantity'] . 'EUR] No tiene premio (de momento), sigue esperando...');
}
echo PHP_EOL;
}
echo '-------------------------------------------', PHP_EOL;
sleep(60);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment