Home > Bash, PHP + MySQL > Send email when medical results appear on lam24.pl

Send email when medical results appear on lam24.pl

Bellow php script will check every 15 min if medical results appear on lam24.pl and send email with notification.


<?php
$url = "https://lam24.pl/wyniki.aspx&quot;;
$zlecenie = "xxxxxxxxx";
$pesel = "xxxxxxxxxxx";

$f = "lam24.ini";
$size = filesize($f);
$fH = fopen($f,"r");
$data = fread($fH,$size);
fclose($fH);
if(strpos($data,'true') !== false) {
exit();
}

$ckfile = tempnam("/tmp", "CURLCOOKIE");
$useragent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.3 Safari/533.2';

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

$html = curl_exec($ch);

curl_close($ch);

preg_match('~~', $html, $viewstate);
preg_match('~~', $html, $eventValidation);

$viewstate = $viewstate[1];
$eventValidation = $eventValidation[1];

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

$postfields = array();
$postfields['__EVENTTARGET'] = "";
$postfields['__EVENTARGUMENT'] = "";
$postfields['__VIEWSTATE'] = $viewstate;
$postfields['__EVENTVALIDATION'] = $eventValidation;
$postfields['Login$UserName'] = $zlecenie;
$postfields['Login$Password'] = $pesel;
$postfields['Login$loginButton'] = 'Pokaż wyniki';

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$ret = curl_exec($ch);
if(strpos($ret,'Nie znaleziono wynik') !== true) {
$fp = fopen($f, 'w');
fwrite($fp, 'true');
fclose($fp);

$to = 'user@gmail.com';
$subject = 'Wyniki Lam24';
$message = 'Automatyczny skrypt, ktory sprawdza dostepnosc wynikow co 15 minut informuje za sa one juz dostepne:' . "\r\n" . 'https://lam24.pl/wyniki.aspx' . "\r\n" .
'Zlecenie: ' . $zlecenie . "\r\n" .
'Pesel: ' . $pesel;
$headers = 'From: user@domain.pl' . "\r\n" .
'Reply-To: user@domain.pl' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
}
curl_close($ch);
?>

crontab:
*/15 * * * * /usr/bin/php /home/n4p1/lam24/lam24.php

Categories: Bash, PHP + MySQL
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: