Last active
November 29, 2024 10:04
-
-
Save mrmuminov/f3a0502dd7b4e2eaec2e44cc5c945b6f to your computer and use it in GitHub Desktop.
Uz Railway ticket checker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function makeRequest() { | |
$url = 'https://eticket.railway.uz/api/v3/trains/availability/space/between/stations'; | |
$headers = [ | |
'Accept: application/json', | |
'Accept-Language: uz', | |
'Connection: keep-alive', | |
'Content-Type: application/json', | |
'Cookie: __stripe_mid=8d265b71-b9cf-47c1-9fd7-98a84ff3d0321f300a; G_ENABLED_IDPS=google; XSRF-TOKEN=836127f7-4efb-45e5-ade1-b63928e34109', | |
'Origin: https://eticket.railway.uz', | |
'Referer: https://eticket.railway.uz/uz/pages/trains-page', | |
'Sec-Fetch-Dest: empty', | |
'Sec-Fetch-Mode: cors', | |
'Sec-Fetch-Site: same-origin', | |
'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', | |
'X-XSRF-TOKEN: 836127f7-4efb-45e5-ade1-b63928e34109', | |
'device-type: BROWSER', | |
'sec-ch-ua: "Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"', | |
'sec-ch-ua-mobile: ?0', | |
'sec-ch-ua-platform: "Linux"', | |
]; | |
$data = [ | |
'direction' => [ | |
[ | |
'depDate' => '08.08.2024', | |
'fullday' => true, | |
'type' => 'Forward', | |
], | |
], | |
'stationFrom' => '2900790', | |
'stationTo' => '2900000', | |
'detailNumPlaces' => 1, | |
'showWithoutPlaces' => 0, | |
]; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
$response = curl_exec($ch); | |
if (curl_errno($ch)) { | |
echo 'Error: ' . curl_error($ch); | |
} | |
curl_close($ch); | |
return $response; | |
} | |
// Run the request every minute | |
while (true) { | |
$response = json_decode(makeRequest(), true); | |
foreach ($response['express']['direction'] as $direction) { | |
foreach ($direction['trains'] as $trains) { | |
foreach ($trains['train'] as $train) { | |
if (!empty($train['places']['cars'])) { | |
$txt = "RAILWAY\n\n"; | |
foreach ($train['places']['cars'] as $car) { | |
$txt.= $car['typeShow'] . ": " . $car['freeSeats'] . "\n"; | |
} | |
file_get_contents("https://api.telegram.org/botTOKEN/sendMessage?chat_id=10536&text=" . urlencode($txt)); | |
} | |
} | |
} | |
} | |
sleep(30); // sleep for 30 seconds | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment