/** * @param EventData $eventData * @return string */ public function populateFacebookEvent(EventData $eventData) { $facebookEvent = $eventData->getFacebookEvent(); $fetchFields = ['id', 'place', 'description', 'ticket_uri', 'start_time', 'end_time', 'attending_count']; try { $facebookEventData = $this->fb->get('/' . $facebookEvent->getFacebookEventId() . '/?fields=' . implode(',', $fetchFields)); } catch (FacebookResponseException $ex) { return $ex->getMessage(); // @TODO: Log stack trace. } $facebookEventData = $facebookEventData->getGraphNode(); if ($facebookEventData->getField('description')) { $facebookEvent->setDescription($facebookEventData->getField('description')); } if ($facebookEventData->getField('ticket_uri')) { $facebookEvent->setTicketUrl($facebookEventData->getField('ticket_uri')); } if ($facebookEventData->getField('start_time')) { $facebookEvent->setStartTime($facebookEventData->getField('start_time')); } if ($facebookEventData->getField('end_time')) { $facebookEvent->setEndTime($facebookEventData->getField('end_time')); } $facebookEvent->setAttendingCount($facebookEventData->getField('attending_count')); if ($facebookEventPlace = $facebookEventData->getField('place')) { $street = []; if ($facebookEventPlace->getField('name')) { $street[] = $facebookEventPlace->getField('name'); } if ($facebookEventPlaceLoc = $facebookEventPlace->getField('location')) { if ($facebookEventPlaceLoc->getField('street')) { $street[] = $facebookEventPlaceLoc->getField('street'); } if ($facebookEventPlaceLoc->getField('latitude') && $facebookEventPlaceLoc->getField('longitude')) { $facebookEvent->setLatitude($facebookEventPlaceLoc->getField('latitude')); $facebookEvent->setLongitude($facebookEventPlaceLoc->getField('longitude')); } } $facebookEvent->setStreet(implode(', ', $street)); } $this->em->persist($facebookEvent); $this->em->flush($facebookEvent); }
/** * @param EventData $eventData * @return EventData */ public function getAllEventData($eventData, OutputInterface $out) { $crawler = (new Client())->request('GET', $eventData->getEventUrl()); $eventData->setEventName($crawler->filter('.page-title')->text()); $count = $crawler->filter('.info-facebook')->count(); if ($count > 0) { preg_match_all("/https:\\/\\/www.facebook.com\\/events\\/([0-9]+)\\/?.*?/", $crawler->filter('.info-facebook .info-text')->html(), $matches); if (isset($matches[1]) and count($matches[1]) > 0) { $facebookEventId = reset($matches[1]); $facebookEvent = new FacebookEvent(); $facebookEvent->setFacebookEventId($facebookEventId); $eventData->setFacebookEvent($facebookEvent); // @TODO: add additional fields to scraper. } } $eventData->setEventImageUrl('http://renginiai.kasvyksta.lt' . $crawler->filter('.main-gallery .thumbnail a.fancybox')->first()->attr('href')); return $eventData; }