parent
2750443612
commit
29ea8882fe
@ -29,6 +29,8 @@ class Deal
|
||||
protected $image1;
|
||||
/** @var string */
|
||||
protected $image2;
|
||||
/** @var \DateTime */
|
||||
protected $datecreation;
|
||||
|
||||
/**
|
||||
* Deal constructor.
|
||||
@ -50,6 +52,13 @@ class Deal
|
||||
$deal->setType(self::TYPE_OFFER);
|
||||
$deal->setBody($crawler->filter('.properties_description')->first()->filter('p')->eq(1)->text());
|
||||
$deal->setPrice($crawler->filter('[itemprop=price]')->first()->attr('content'));
|
||||
$date_node = $crawler->filter('[itemprop=availabilityStarts]')->first();
|
||||
$date = \DateTime::createFromFormat('Y-m-d', $date_node->attr('content'));
|
||||
$hours = current($date_node->extract(['_text']));
|
||||
$hours = substr($hours, strpos($hours, 'à')+2);
|
||||
list($hour, $min) = explode(':', $hours);
|
||||
$date->setTime((int) $hour, (int) $min);
|
||||
$deal->setDateCreation($date);
|
||||
if ($crawler->filter('.item_photo')->count() > 0) {
|
||||
$script = $crawler ->filter('.item_photo')->first()->nextAll()
|
||||
->filter('script')->first()->html();
|
||||
@ -57,7 +66,7 @@ class Deal
|
||||
$urls = $urls[1];
|
||||
$images = [];
|
||||
foreach ($urls as $i => $url) {
|
||||
$images[] = [sprintf('setImage%s', $i) => str_replace('thumb','large', $url)];
|
||||
$images[] = [sprintf('setImage%s', $i) => str_replace('thumb', 'large', $url)];
|
||||
}
|
||||
} else {
|
||||
$images = $crawler->filter('[data-popin-content]')->each(
|
||||
@ -236,6 +245,24 @@ class Deal
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getDateCreation()
|
||||
{
|
||||
return $this->datecreation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $price
|
||||
* @return Deal
|
||||
*/
|
||||
public function setDateCreation($datecreation)
|
||||
{
|
||||
$this->datecreation = $datecreation;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Account
|
||||
*/
|
||||
@ -279,8 +306,8 @@ class Deal
|
||||
mkdir($save_dir);
|
||||
}
|
||||
file_put_contents(sprintf('%s/%s', $save_dir, 'data.json'), $this->toJSON());
|
||||
foreach (range(0,2) as $i) {
|
||||
$image = sprintf('image%u',$i);
|
||||
foreach (range(0, 2) as $i) {
|
||||
$image = sprintf('image%u', $i);
|
||||
if (empty($this->$image)) {
|
||||
break;
|
||||
}
|
||||
@ -293,7 +320,7 @@ class Deal
|
||||
curl_close($ch);
|
||||
fclose($fp);
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user