Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.22 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Andreas
  5.  * Date: 07.03.2017
  6.  * Time: 12:30
  7.  */
  8. $filename = "/home/andauhApps/examParser/hasChanged.txt";
  9. $filename2 = "/home/andauhApps/examParser/hasChangedOld.txt";
  10. //$filename = "D:/Dev/xampp/htdocs/examParser/hasChanged.txt";
  11.  
  12. $feed = simplexml_load_file('http://jexam.inf.tu-dresden.de/rss.xml');
  13.  
  14. $index = 0;
  15. $toCompare = '';
  16. while($index < count($feed->channel[0]->item)){
  17.     $toCompare = (string)$feed->channel[0]->item[$index]->title[0];
  18.     if(preg_match('/Prüfungsergebnisse/', $toCompare) && preg_match('/SS 2017/', $toCompare)){
  19.         break;
  20.     }
  21.     $index++;
  22. }
  23.  
  24.  
  25. $feedElement = (string) $feed->channel[0]->item[$index]->description[0];
  26. $feedElementStripped = substr($feedElement, 0, strpos($feedElement, '<b><span style'));
  27.  
  28. $file = fopen($filename,"r+");
  29. $fileContent = fgets($file, 10000);
  30.  
  31. file_put_contents($filename2, $fileContent);
  32.  
  33. if(strcmp($fileContent, $feedElementStripped) != 0){
  34.     file_put_contents($filename, '');
  35.     rewind($file);
  36.     fwrite($file, $feedElementStripped);
  37.     sendMyselfMail($feedElementStripped);
  38. }
  39. else{
  40.     echo "isEqual, do nothing\n";
  41. }
  42.  
  43. fclose($file);
  44.  
  45. function notify(){
  46.     sendMyselfMail();
  47. }
  48.  
  49. function sendMyselfMail($feedElement){
  50.     include_once 'phpmailer/PHPMailerAutoload.php';
  51.     $oMailer = new PHPMailer;
  52.     $oMailer->CharSet = 'UTF-8';
  53.  
  54.     $oMailer->isSMTP();
  55.     $oMailer->Host = 'smtp.web.de';
  56.     $oMailer->SMTPAuth = true;
  57.     $oMailer->Username = 'andhub_spam';
  58.     $oMailer->Password = '********';
  59.     $oMailer->SMTPSecure = 'tls';
  60.     $oMailer->Port = 587;
  61.  
  62.     $oMailer->From = 'andhub_spam@web.de';
  63.     $oMailer->FromName = 'andhub';
  64.     $oMailer->addAddress( 'andreas.huber2@mailbox.tu-dresden.de', 'Andreas Huber' );
  65.  
  66.     $oMailer->isHTML( true );
  67.     $oMailer->Subject = 'jExam';
  68.     $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>';
  69.     $oMailer->AltBody = strip_tags( $oMailer->Body );
  70.  
  71.  
  72.     if ( !$oMailer->send() ) {
  73.  
  74.         echo 'Something\'s went wrong!\n';
  75.         exit;
  76.  
  77.     }
  78.  
  79.     echo 'Mail sent!\n';
  80. }
  81.  
  82.  
  83. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement