Refactored CinemaCity repertoire fetcher.
This commit is contained in:
@@ -26,69 +26,62 @@ class CinemaCinemaCity implements Cinema
|
||||
if (is_null($this->cinemaId) || is_null($this->day))
|
||||
throw new \Exception('Day or cinemaid not set.');
|
||||
|
||||
if (!is_array($this->cinemaId)) {
|
||||
$this->cinemaId = (array)$this->cinemaId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$url = 'https://www.cinema-city.pl/scheduleInfo?locationId=1010308&date=' . $date . '&venueTypeId=0&hideSite=false&openedFromPopup=1';
|
||||
|
||||
$document = new Document($url, true);
|
||||
$text = "Repertuar Cinema-City\n";
|
||||
$text .= str_replace('/', '-', $date) . "\n\n";
|
||||
|
||||
$movies = $document->find('table tbody tr');
|
||||
foreach ($movies as $movie) {
|
||||
// dump($movie);
|
||||
$text .= $movie->find('.featureLink')[0]->text() . "\n";
|
||||
$hours = [];
|
||||
foreach ($movie->find('.prsnt a') as $projection) {
|
||||
$hours[] = trim($projection->text());
|
||||
}
|
||||
$text .= implode(', ', $hours) . "\n\n";
|
||||
}
|
||||
return $text;
|
||||
// if (!is_array($this->cinemaId)) {
|
||||
// $this->cinemaId = (array)$this->cinemaId;
|
||||
// }
|
||||
$url = 'https://www.cinema-city.pl/pgm-list-byfeat?si=' . $this->cinemaId . '&sort=cin&bd=' . $this->day;
|
||||
|
||||
return file_get_contents($url);
|
||||
|
||||
}
|
||||
|
||||
function parseRepertoire()
|
||||
{
|
||||
$documents = $this->fetchRepertorire();
|
||||
$cinemas = [];
|
||||
foreach ($documents as $document) {
|
||||
$movies = [];
|
||||
foreach ($document->find('.seance') as $seans) {
|
||||
$movie = [];
|
||||
$movie['title'] = trim($seans->find('.movie-title')[0]->text());
|
||||
$document = $this->fetchRepertorire();
|
||||
$document = json_decode($document);
|
||||
|
||||
$hours = [];
|
||||
foreach ($seans->find('.time li') as $hour) {
|
||||
$hours[] = $hour->text();
|
||||
|
||||
// $cinemaData = [];
|
||||
// $text = "Repertuar Cinema-City\n";
|
||||
// $text .= str_replace('/', '-', $this->day) . "\n\n";
|
||||
$movies = [];
|
||||
|
||||
$date = date('d/m/Y', strtotime($this->day));
|
||||
foreach ($document as $movieData) {
|
||||
$movie = [];
|
||||
$movie['title'] = $movieData->n;
|
||||
$movie['hours'] = [];
|
||||
|
||||
foreach ($movieData->BD as $projections) {
|
||||
if ($projections->date == $date) {
|
||||
foreach ($projections->P as $projection) {
|
||||
|
||||
// var_dump($projection);
|
||||
// die();
|
||||
$movie['hours'][] = $projection->time;
|
||||
}
|
||||
}
|
||||
$movie['hours'] = array_unique($hours);
|
||||
}
|
||||
if (count($movie['hours']) > 0) {
|
||||
$movies[] = $movie;
|
||||
}
|
||||
$cinemas[] = $movies;
|
||||
|
||||
}
|
||||
return $cinemas;
|
||||
|
||||
|
||||
return $movies;
|
||||
}
|
||||
|
||||
function convertToPrint()
|
||||
{
|
||||
$cinemas = $this->parseRepertoire();
|
||||
$text = '';
|
||||
foreach ($cinemas as $cinemaId => $filmy) {
|
||||
$text .= "Repertuar " . $this->cinemas[$this->cinemaId[$cinemaId]] . "\n";
|
||||
$text .= date_create()->modify("+$this->day day")->format('d-m-Y') . "\n\n";
|
||||
|
||||
foreach ($filmy as $film) {
|
||||
$text .= $film['title'] . "\n";
|
||||
$text .= implode(', ', array_unique($film['hours'])) . "\n\n";
|
||||
}
|
||||
$text .= "\n";
|
||||
$text = "Repertuar Cinema-City\n";
|
||||
$text .= $this->day . "\n\n";
|
||||
|
||||
foreach ($cinemas as $movie) {
|
||||
$text .= $movie['title'] . "\n";
|
||||
$text .= implode(',', $movie['hours'] ). "\n\n";
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user