Guest User

Untitled

a guest
Jan 22nd, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.61 KB | None | 0 0
  1. function refreshAll()
  2.                 {
  3.                    
  4.                        
  5.                                    
  6.                             $hostname = "localhost";
  7.                             $username = "trending_alex";
  8.                                 $pass = "TariqAlex95";
  9.                                 $db_name = "trending_alex";
  10.                                  $conn_string = "mysql:host=$hostname;dbname=$db_name";
  11.                                 $dbh = new PDO($conn_string, $username, $pass);
  12.                                 $sql = "SELECT * from news";
  13.                                 $pdo_i = $dbh->query($sql);
  14.                                 $arr = $pdo_i->fetchALL(PDO::FETCH_ASSOC);
  15.                                
  16.                                
  17.                                
  18.                                
  19.                                $file = "http://seekingalpha.com/feed.xml";
  20.                                 $xml = simplexml_load_file($file) or die ("Can't read $file!");
  21.                                 foreach ($xml->channel->item as $it) {
  22.                              //   if ($it->category=="AKS" || $it->category=="GLD" || $it->category=="AAPL" || $it->category=="FB" || $it->category=="TWLO" || $it->category=="NVDA"  || $it->category=="NVDA" || $it->category=="X" )            
  23.                                 // echo
  24.                                 //   "<a href='".$it->link."'>".
  25.  
  26.                                // $it->title." ".$it->pubDate ."<br /></a>";
  27.                                 $trig=0;
  28.                                 foreach($arr as $news) {
  29.                                        
  30.                                     if ($news['source']=="seekingalpha" && $news["newsid"]==$it->guid)
  31.                                     {
  32.                                         $trig=1;
  33.                                         break;
  34.                                     }
  35.                                 }
  36.                              
  37.                              
  38.                                 if ($trig==0)
  39.                                 {
  40.                                          
  41.                                             $sql1 = "INSERT INTO news(title) ";
  42.                                             $sql1 .= "VALUES ('".$it->title."')";
  43.                                          $dbh->exec($sql1) or die($dbh->errorinfo());
  44.                                             //var_dump($sql1);
  45.                                 }
  46.                                
  47.                    
  48.                                 }
  49.                  $dbh = null;
  50.                 }
Add Comment
Please, Sign In to add comment