public function DoScrape($location)
 {
     // scrape a given location
     $this->feed_url = "http://feeds.feedburner.com/groupon" . $this->location_map[$location];
     $data_feed = file_get_contents($this->feed_url);
     $xml = simplexml_load_string($data_feed);
     $channel = $xml->channel;
     // parent:: d($channel);
     // exit();
     foreach ($channel->item as $item) {
         // loop through each item
         parent::SetQuery("SELECT * FROM `aggregate_deal` WHERE deal_url='{$item->link}'");
         $exists = parent::CountDBResults();
         if (!$exists) {
             // deal doesn't exist in the database yet
             //echo $item->title . "<br/>";
             preg_match_all('#\\$[0-9]{1,3}(?:,?[0-9]{3})*(?:\\.[0-9]{2})?#', $item->title, $out);
             $pattern = "/src=[\"']?([^\"']?.*(png|jpg|gif))[\"']?/i";
             preg_match_all($pattern, $item->description, $images);
             parent::SetQuery("INSERT INTO `aggregate_deal`\n\t\t\t\tVALUES ('','','{$location}','','',\n\t\t\t\t'" . addslashes($item->title) . "',\n\t\t\t\t'" . addslashes($item->description) . "',\n\t\t\t\t'{$item->link}',\n\t\t\t\t'" . str_replace("\$", "", $out[0][0]) . "',\n\t\t\t\t'" . str_replace("\$", "", $out[0][1]) . "',\n\t\t\t\t'1',\n\t\t\t\t'" . strtotime('midnight') . "',\n\t\t\t\tnow(),\n\t\t\t\t'{$images[1][0]}','')");
             parent::SimpleQuery();
         }
         parent::SetQuery("SELECT * FROM `aggregate_deal`");
         $results = parent::DoQuery();
         foreach ($results as $result) {
             // loop through each result to see if it has expired, delete it if it has
             $expired = mktime(0, 0, 0, date("m"), date("d", $result["time_added"]) + 1, date("Y"));
             if (time() > $expired) {
                 parent::SetQuery("DELETE FROM `aggregate_deal` WHERE aggregate_deal_id='{$result["deal_id"]}'");
                 parent::SimpleQuery();
             }
         }
     }
 }
 public function DoScrape($location)
 {
     // scrape a given location
     $this->feed_url = "http://feeds.feedburner.com/groupon" . $this->location_map[$location];
     $data_feed = file_get_contents($this->feed_url);
     $xml = simplexml_load_string($data_feed);
     $channel = $xml->channel;
     foreach ($channel->item as $item) {
         // loop through each item
         parent::SetQuery("SELECT * FROM `table_dealaggregator` WHERE deal_url='{$item->link}'");
         $exists = parent::CountDBResults();
         if (!$exists) {
             // deal doesn't exist in the database yet
             //echo $item->title . "<br/>";
             preg_match_all('#\\$[0-9]{1,3}(?:,?[0-9]{3})*(?:\\.[0-9]{2})?#', $item->title, $out);
             ///print_r( $out ); exit;
             parent::SetQuery("INSERT INTO `table_dealaggregator`\n\t\t\t\tVALUES ('','','{$location}','','',\n\t\t\t\t'" . addslashes($item->title) . "',\n\t\t\t\t'" . addslashes($item->description) . "',\n\t\t\t\t'{$item->link}',\n\t\t\t\t'" . str_replace("\$", "", $out[0][0]) . "',\n\t\t\t\t'" . str_replace("\$", "", $out[0][1]) . "',\n\t\t\t\t'1')");
             parent::SimpleQuery();
         }
     }
 }
Example #3
0
 public function insert($url, $title, $img_url, $source_id, $region_id, $price, $value, $time_added, $vendor_name, $addresses, $description)
 {
     parent::SetQuery("SELECT * FROM `aggregate_deal` WHERE deal_url='{$url}'");
     $exists = parent::CountDBResults();
     if (!$exists) {
         parent::SetQuery("INSERT INTO `aggregate_deal`\n\t\t\t\t\t(\n\t\t\t\t\taggregate_deal_region_id,\n\t\t\t\t\ttitle, \n\t\t\t\t\tdeal_url, \n\t\t\t\t\timg_url,\n\t\t\t\t\taggregate_deal_source_id,\n\t\t\t\t\tdate,\n\t\t\t\t\tprice,\n\t\t\t\t\tvalue,\n\t\t\t\t\ttime_added,\n\t\t\t\t\tvendor_name,\n\t\t\t\t\tdescription\n\t\t\t\t\t)\n\t\t\t\t\tVALUES (\n\t\t\t\t\t'{$region_id}',\n\t\t\t\t\t'" . addslashes($title) . "',\n\t\t\t\t\t'{$url}',\n\t\t\t\t\t'{$img_url}',\n\t\t\t\t\t{$source_id},\n\t\t\t\t\tnow(),\n\t\t\t\t\t{$price},\n\t\t\t\t\t{$value},\n\t\t\t\t\t{$time_added},\n\t\t\t\t\t'{$vendor_name}',\n\t\t\t\t\t'{$description}'\n\t\t\t\t\t)");
         $mysql_insert_id = parent::InsertQuery();
         if ($vendor_name != "-") {
             foreach ($addresses as $address) {
                 foreach ($address as $k => $v) {
                     if ($k == 'address') {
                         $address = $v;
                     }
                     if ($k == 'city') {
                         $city = $v;
                     }
                     if ($k == 'state') {
                         $state = $v;
                     }
                     if ($k == 'zipcode') {
                         $zipcode = $v;
                     }
                     if ($k == 'latitude') {
                         $latitude = $v;
                     }
                     if ($k == 'longitude') {
                         $longitude = $v;
                     }
                 }
                 $address = addslashes($address);
                 parent::SetQuery("INSERT INTO aggregate_deal_location (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\taddress_all,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\taddress, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tcity, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tstate, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tzipcode, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tlatitude, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tlongitude, \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\taggregate_deal_id)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvalues(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$address}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$address}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$city}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$state}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$zipcode}', \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$latitude}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$longitude}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{$mysql_insert_id}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t) ");
                 $mysql_insert_id = parent::InsertQuery();
             }
         } else {
             $mysql_insert_id = 0;
         }
     }
 }
 public function getDealsMissingInfo()
 {
     parent::SetQuery("SELECT aggregate_deal_id,  deal_url FROM aggregate_deal WHERE aggregate_deal_source_id = 1");
     $arrays = parent::DoQuery();
     return $arrays;
 }
 public function insertMissingInfo($address, $aggregate_deal_id)
 {
     parent::SetQuery("INSERT INTO aggregate_deal_location (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\taddress_all,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\taggregate_deal_id)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tvalues(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t'{$address}',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t{$aggregate_deal_id}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t) ");
     $mysql_insert_id = parent::InsertQuery();
 }