Advertisement
Guest User

Untitled

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