Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. function parseAd() {
  2.  
  3. $bolha = file_get_contents("https://www.bolha.com/index.php?ctl=search_ads&keywords=Canon+60D&sort=new");
  4.  
  5. $first_date = true;
  6. $date_tmp = "";
  7. $url_string = "";
  8.  
  9. while ($pos = strpos($bolha, "EntityList-item EntityList-item--Regular")) {
  10. $bolha = substr($bolha, $pos, -1);
  11.  
  12. $pos = strpos($bolha, 'class="link" href="');
  13. $bolha = substr($bolha, $pos, -1);
  14.  
  15. $pos2 = strpos($bolha, '>');
  16. $url = substr($bolha, 19, $pos2 - 20);
  17.  
  18. $pos = strpos($bolha, '>');
  19. $bolha = substr($bolha, $pos + 1, -1);
  20.  
  21. $pos2 = strpos($bolha, '</a>');
  22. $title = substr($bolha, 0, $pos2);
  23.  
  24.  
  25. $pos = strpos($bolha, 'pubdate">');
  26. $bolha = substr($bolha, $pos + 9, -1);
  27.  
  28. $pos2 = strpos($bolha, '</time>');
  29. $end2 = substr($bolha, 0, $pos2 - 1);
  30.  
  31.  
  32. if (true || strpos($title, '60D') !== false) {
  33. $cnt = DB::table("test")->get();
  34.  
  35. foreach ($cnt as $row) {
  36. $last_known = new DateTime($row->last_date);
  37. $new_ad = new DateTime($end2);
  38.  
  39. if ($new_ad > $last_known) {
  40. if ($first_date) {
  41.  
  42. $dateArray = explode(".", $end2);
  43. $date_tmp = $dateArray[2] . "-" . $dateArray[1] . '-' . $dateArray[0];
  44.  
  45. $first_date = false;
  46. }
  47.  
  48. $url_string .= "https://www.bolha.com" . $url . "<br>";
  49. } else {
  50. break 2;
  51. }
  52. }
  53. }
  54. }
  55.  
  56.  
  57. if (!$first_date) {
  58.  
  59. $to = 'oskar.semec1@gmail.com,mitja.usenik@gmail.com';
  60. $subject = 'Canon 60D';
  61. $message = "Nov oglas: " . $url_string;
  62. $headers = 'From: festivaljezikov@lingfest.eu' . "\r\n";// .
  63. // 'X-Mailer: PHP/' . phpversion();
  64. $headers .= "MIME-Version: 1.0\r\n";
  65. $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
  66.  
  67. mail($to, $subject, $message, $headers);
  68.  
  69. DB::table("test")->update(["last_date" => sprintf("%s", $date_tmp)]);
  70. }
  71.  
  72.  
  73. $prodajko = file_get_contents("https://www.prodajko.si/iskanje?q=60D");
  74.  
  75. $pos = strpos($prodajko, "card-details");
  76. $prodajko = substr($prodajko, $pos, -1);
  77.  
  78. $pos = strpos($prodajko, 'href="');
  79. $prodajko = substr($prodajko, $pos + 6, -1);
  80.  
  81. $pos2 = strpos($prodajko, '">');
  82. $prodajko = substr($prodajko, 0, $pos2);
  83.  
  84.  
  85. $cnt = DB::table("test")->get();
  86.  
  87. foreach ($cnt as $row) {
  88. $last_known = $row->url;
  89. if ($prodajko != $last_known || $last_known === NULL) {
  90. $url = "https://www.prodajko.si" . $prodajko;
  91.  
  92. DB::table("test")->update(["url" => sprintf("%s", $prodajko)]);
  93.  
  94. $to = 'oskar.semec1@gmail.com,mitja.usenik@gmail.com';
  95. $subject = 'Canon 60D';
  96. $message = 'Nov oglas: ' . $url;
  97. $headers = 'From: festivaljezikov@lingfest.eu' . "\r\n" .
  98. 'X-Mailer: PHP/' . phpversion();
  99.  
  100. mail($to, $subject, $message, $headers);
  101. }
  102.  
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement