Skip to content

Instantly share code, notes, and snippets.

@mrmuminov
Last active December 16, 2025 04:44
Show Gist options
  • Select an option

  • Save mrmuminov/f3a0502dd7b4e2eaec2e44cc5c945b6f to your computer and use it in GitHub Desktop.

Select an option

Save mrmuminov/f3a0502dd7b4e2eaec2e44cc5c945b6f to your computer and use it in GitHub Desktop.
Uz Railway ticket checker
<?php
$interval = getenv("APP_INTERVAL"); // 2025-12-31
$date = getenv("APP_DATE"); // 2025-12-31
$depStationCode = getenv("APP_FROM"); // 2900000
$arvStationCode = getenv("APP_TO"); // 2900680
$maxCost = getenv("APP_MAX_COST");
$botToken = getenv("APP_BOT_TOKEN");
$chatId = getenv("APP_CHAT_ID");
function makeRequest() {
$url = 'https://eticket.railway.uz/api/v3/handbook/trains/list';
$headers = [
'Accept: application/json',
'Accept-Encoding: gzip, deflate, br, zstd',
'Accept-Language: uz',
'Cache-Control: no-cache',
'Connection: keep-alive',
'Content-Type: application/json',
'Cookie: __stripe_mid=e1f01afa-c761-4b14-bd37-b59c6e3b3fb08ce5d1; G_ENABLED_IDPS=google; XSRF-TOKEN=d0d1aae8-4de1-49c6-965b-5b444c66a6bd; __stripe_sid=ed68b0fe-c1f4-487f-8f5e-4a574b84c6a32580fe',
'Origin: https://eticket.railway.uz',
'X-XSRF-TOKEN: d0d1aae8-4de1-49c6-965b-5b444c66a6bd',
];
$data = [
"directions" => [
"forward" => [
"date" => $date,
"depStationCode" => $depStationCode,
"arvStationCode" => $arvStationCode
]
]
];
$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 $interval per second
while (true) {
print_r("Next loop at: " . date("Y-m-d H:i:s") . "\n");
$response = json_decode(makeRequest(), true);
foreach ($response['data']['directions']['forward']['trains'] as $train) {
$text = "RAILWAY\n\n";
$isExists = false;
foreach ($train['cars'] as $car) {
foreach ($car['tariffs'] as $tariff) {
if ($tariff['tariff'] <= $maxCost) {
$isExists = true;
$text.= $car['freeSeats'] . " ta joy | ". $train['type'] . ' - '. $train['number'] . ' - ' . $train['departureDate'] . "\n";
}
}
}
if ($isExists){
print_r($text);
}
file_get_contents("https://api.telegram.org/bot" . $botToken . "/sendMessage?chat_id=" . $chatId . "&text=" . urlencode($txt));
}
sleep($interval); // sleep for $interval seconds
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment