Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: Andreas
- * Date: 07.03.2017
- * Time: 12:30
- */
- $filename = "/home/andauhApps/examParser/hasChanged.txt";
- $filename2 = "/home/andauhApps/examParser/hasChangedOld.txt";
- //$filename = "D:/Dev/xampp/htdocs/examParser/hasChanged.txt";
- $feed = simplexml_load_file('http://jexam.inf.tu-dresden.de/rss.xml');
- $index = 0;
- $toCompare = '';
- while($index < count($feed->channel[0]->item)){
- $toCompare = (string)$feed->channel[0]->item[$index]->title[0];
- if(preg_match('/Prüfungsergebnisse/', $toCompare) && preg_match('/SS 2017/', $toCompare)){
- break;
- }
- $index++;
- }
- $feedElement = (string) $feed->channel[0]->item[$index]->description[0];
- $feedElementStripped = substr($feedElement, 0, strpos($feedElement, '<b><span style'));
- $file = fopen($filename,"r+");
- $fileContent = fgets($file, 10000);
- file_put_contents($filename2, $fileContent);
- if(strcmp($fileContent, $feedElementStripped) != 0){
- file_put_contents($filename, '');
- rewind($file);
- fwrite($file, $feedElementStripped);
- sendMyselfMail($feedElementStripped);
- }
- else{
- echo "isEqual, do nothing\n";
- }
- fclose($file);
- function notify(){
- sendMyselfMail();
- }
- function sendMyselfMail($feedElement){
- include_once 'phpmailer/PHPMailerAutoload.php';
- $oMailer = new PHPMailer;
- $oMailer->CharSet = 'UTF-8';
- $oMailer->isSMTP();
- $oMailer->Host = 'smtp.web.de';
- $oMailer->SMTPAuth = true;
- $oMailer->Username = 'andhub_spam';
- $oMailer->Password = '********';
- $oMailer->SMTPSecure = 'tls';
- $oMailer->Port = 587;
- $oMailer->From = 'andhub_spam@web.de';
- $oMailer->FromName = 'andhub';
- $oMailer->addAddress( 'andreas.huber2@mailbox.tu-dresden.de', 'Andreas Huber' );
- $oMailer->isHTML( true );
- $oMailer->Subject = 'jExam';
- $oMailer->Body = '<h1>Änderung in XML-Feed von <a href ="https://jexam.inf.tu-dresden.de/de.jexam.web.v4.5/spring/welcome">jExam</a></h1> <h2> Eingepflegt: </h2> <p>' .$feedElement. '</p>';
- $oMailer->AltBody = strip_tags( $oMailer->Body );
- if ( !$oMailer->send() ) {
- echo 'Something\'s went wrong!\n';
- exit;
- }
- echo 'Mail sent!\n';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement