diff --git a/app/Http/Controllers/Repertoire.php b/app/Http/Controllers/Repertoire.php index 98dbf5d..4508ecc 100644 --- a/app/Http/Controllers/Repertoire.php +++ b/app/Http/Controllers/Repertoire.php @@ -2,15 +2,17 @@ namespace App\Http\Controllers; +use App\Paper\CinemaCinemaCity; +use App\Paper\CinemaGdynskieCentrumFilmowe; +use App\Paper\CinemaHelios; use App\Paper\CinemaMultikino; -use DiDom\Document; use App\Paper\Paper; class Repertoire extends Controller { private $main; - private $icon = '/small/film.png'; + private $icon = 'film'; public function __construct() { @@ -20,200 +22,112 @@ class Repertoire extends Controller public function today_cinemacity() { - $date = date('d/m/Y'); - $repertuarText = $this->cinemacityRepertuar($date); - $this->main->sendPrint('', $repertuarText, $this->icon, $this->icon); + $cinemacity = new CinemaCinemaCity(); + $cinemacity->setCinemaId(1010912); + $cinemacity->setDay(date('Y-m-d')); + $repertuarText = $cinemacity->convertToPrint(); + + $this->main->sendPrint('', $repertuarText, $this->icon); return back(); } public function tomorrow_cinemacity() { - $date = new \DateTime(); - $date->modify('+1 day'); - $repertuarText = $this->cinemacityRepertuar($date->format('d/m/Y')); - $this->main->sendPrint('', $repertuarText, $this->icon, $this->icon); + $cinemacity = new CinemaCinemaCity(); + $cinemacity->setCinemaId(1010912); + $cinemacity->setDay(date_create()->modify('+1 day')->format('Y-m-d')); + $repertuarText = $cinemacity->convertToPrint(); + + $this->main->sendPrint('', $repertuarText, $this->icon); return back(); } - public function cinemacityRepertuar($date) - { - $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; - } - - - private function multikinoRepertuar($date) - { - - $text = ''; - $repertuar = json_decode(file_get_contents('https://multikino.pl/pl/repertoire/cinema/seances?id=4&from=' . $date)); - $text .= "Repertuar Multikino Gdańsk\n"; - $text .= $date . "\n\n"; - - foreach ($repertuar->results as $movie) { - $text .= $movie->title . "\n"; - $text .= $movie->print_version . "\n"; - - $hours = []; - foreach ($movie->seances as $seans) { - $hours[] = date('H:i', strtotime($seans->beginning_date)); - } - $text .= implode(', ', $hours) . "\n\n"; - } - - return $text; - } public function today_multikino() { $multikino = new CinemaMultikino(); - $repertuarText = $multikino->convertToPrint(date('Y-m-d'), 4); + $multikino->setCinemaId(4); + $multikino->setDay(date('Y-m-d')); + + $repertuarText = $multikino->convertToPrint(); $this->main->sendPrint('', $repertuarText, $this->icon); return back(); } public function tomorrow_multikino() { - $date = new \DateTime(); - $date->modify('+1 day'); - $multikino = new CinemaMultikino(); - $repertuarText = $multikino->convertToPrint($date->format('Y-m-d'), 4); + $multikino->setDay(date_create()->modify('+1 day')->format('Y-m-d')); + $multikino->setCinemaId(4); + + $repertuarText = $multikino->convertToPrint(); $this->main->sendPrint('', $repertuarText, $this->icon); return back(); - - -// $repertuarText = $this->multikinoRepertuar($date->format('Y-m-d')); -// $this->main->sendPrint('', $repertuarText); -// return back(); } public function tomorrow_gdynskiecentrumfilmowe() { - $date = new \DateTime(); - $date->modify('+1 day'); + $gdynskieCentrumFilmowe = new CinemaGdynskieCentrumFilmowe(); + $gdynskieCentrumFilmowe->setDay(date_create()->modify('+1 day')->format('d_m_Y')); + $repertuarText = $gdynskieCentrumFilmowe->convertToPrint(); - $repertuarText = $this->gdynskieCentrumFilmowe($date->format('d_m_Y')); $this->main->sendPrint('', $repertuarText, $this->icon); return back(); } public function today_gdynskiecentrumfilmowe() { - $date = date('d_m_Y'); - $repertuarText = $this->gdynskieCentrumFilmowe($date); + $gdynskieCentrumFilmowe = new CinemaGdynskieCentrumFilmowe(); + $gdynskieCentrumFilmowe->setDay(date('d_m_y')); + $repertuarText = $gdynskieCentrumFilmowe->convertToPrint(); + $this->main->sendPrint('', $repertuarText, $this->icon); return back(); } public function today_helios() { - $this->main->sendPrint('', $this->helios(0, 2), $this->icon); - $this->main->sendPrint('', $this->helios(0, 49)); + $helios = new CinemaHelios(); + $helios->setDay(0); + $helios->setCinemaId([2, 49]); + $helios->convertToPrint(); + + $repertuarText = $helios->convertToPrint(); + $this->main->sendPrint('', $repertuarText, $this->icon); + return back(); } public function tomorrow_helios() { - $this->main->sendPrint('', $this->helios(1, 2), $this->icon); - $this->main->sendPrint('', $this->helios(1, 49)); + $helios = new CinemaHelios(); + $helios->setDay(1); + $helios->setCinemaId([2, 49]); + $helios->convertToPrint(); + + $repertuarText = $helios->convertToPrint(); + $this->main->sendPrint('', $repertuarText, $this->icon); + return back(); } public function today_repertoire() { - $this->today_multikino(); $this->today_cinemacity(); $this->today_helios(); $this->today_gdynskiecentrumfilmowe(); - } public function tomorrow_repertoire() { - $this->tomorrow_multikino(); $this->tomorrow_cinemacity(); $this->tomorrow_helios(); $this->tomorrow_gdynskiecentrumfilmowe(); } - private function helios($day, $cinemaId) - { - $url = 'http://www.helios.pl/2,Gdansk/Repertuar/axRepertoire/?dzien=' . $day . '&kino=' . $cinemaId; - - - $data = json_decode(file_get_contents($url)); - $document = new Document(); - $data->html = str_replace(["\n", "\t"], '', $data->html); - $document->loadHtml($data->html); - - - $cinemas = [2 => 'Helios Alfa', 49 => 'Helios Metropolia']; - - $text = ''; - $text .= "Repertuar $cinemas[$cinemaId]\n"; - - $date = new \DateTime(); - $date->modify('+' . $day . ' day'); - - $text .= $date->format('d-m-Y') . "\n\n"; - - - foreach ($document->find('.seance') as $seans) { - $text .= trim($seans->find('.movie-title')[0]->text()) . "\n"; - $hours = []; - foreach ($seans->find('.time li') as $hour) { - $hours[] = $hour->text(); - } - $text .= implode(', ', array_unique($hours)) . "\n\n"; - } - - return $text; - } - - - private function gdynskieCentrumFilmowe($date) - { - - - $url = 'http://www.gdynskiecentrumfilmowe.pl/kino_studyjne/repertuar/,' . strtotime($date) . ',_' . $date . '.html'; - $document = new Document($url, true); - $text = ''; - $text .= "Repertuar Gdyńskie Centrum Filmowe\n"; - $text .= str_replace('_', '-', $date) . "\n\n"; - - $movies = $document->find('.articles .article-item'); - foreach ($movies as $movie) { - - $text .= $movie->find('.item-title-int')[0]->text() . "\n"; - $hours = []; - foreach ($movie->find('.projection span') as $projection) { - $hours[] = $projection->innerHtml(); - } - $text .= implode(', ', array_unique($hours)) . "\n\n"; - } - - return $text; - } - } diff --git a/app/Paper/CinemaCinemaCity.php b/app/Paper/CinemaCinemaCity.php new file mode 100644 index 0000000..4e23d9c --- /dev/null +++ b/app/Paper/CinemaCinemaCity.php @@ -0,0 +1,88 @@ +cinemaId = $cinemaId; + } + + public function setDay($day) + { + $this->day = $day; + } + + function fetchRepertorire() + { + 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/pgm-list-byfeat?si=' . $this->cinemaId . '&sort=cin&bd=' . $this->day; + + return file_get_contents($url); + + } + + function parseRepertoire() + { + $document = $this->fetchRepertorire(); + $document = json_decode($document); + + +// $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; + } + } + } + if (count($movie['hours']) > 0) { + $movies[] = $movie; + } + + } + + + return $movies; + } + + function convertToPrint() + { + $cinemas = $this->parseRepertoire(); + + $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; + } +} \ No newline at end of file diff --git a/app/Paper/CinemaGdynskieCentrumFilmowe.php b/app/Paper/CinemaGdynskieCentrumFilmowe.php new file mode 100644 index 0000000..11fb937 --- /dev/null +++ b/app/Paper/CinemaGdynskieCentrumFilmowe.php @@ -0,0 +1,82 @@ +cinemaId = $cinemaId; + } + + public function setDay($day) + { + $this->day = $day; + + + } + + function fetchRepertorire() + { + if (is_null($this->day)) + throw new \Exception('Day not set.'); + +// if (!is_array($this->cinemaId)) { +// $this->cinemaId = (array)$this->cinemaId; +// } + $url = 'http://www.gdynskiecentrumfilmowe.pl/kino_studyjne/repertuar/,' . strtotime($this->day) . ',_' . $this->day . '.html'; + return file_get_contents($url); + + } + + function parseRepertoire() + { + $rawPage = $this->fetchRepertorire(); + + $document = new Document(); + $document->loadHtml($rawPage); + $moviesData = []; + + + + $movies = $document->find('.articles .article-item'); + foreach ($movies as $movie) { + + $movieData = []; + $movieData['title'] = $movie->first('.item-title-int::text'); + $movieData['hours'] = []; + foreach ($movie->find('.projection span') as $projection) { + $movieData['hours'][] = $projection->innerHtml(); + } +// $text .= implode(', ', array_unique($hours)) . "\n\n"; + $moviesData[] = $movieData; + } + + return $moviesData; + + } + + function convertToPrint() + { + $movies = $this->parseRepertoire(); + + $text = ''; + $text .= "Repertuar Gdyńskie Centrum Filmowe\n"; + $text .= str_replace('_', '-', $this->day) . "\n\n"; + + foreach ($movies as $movie) { + + $text .= $movie['title']. "\n"; + $text .= implode(', ', array_unique($movie['hours'])). "\n\n"; + } + + return $text; + } +} \ No newline at end of file diff --git a/app/Paper/CinemaHelios.php b/app/Paper/CinemaHelios.php new file mode 100644 index 0000000..a351c0c --- /dev/null +++ b/app/Paper/CinemaHelios.php @@ -0,0 +1,86 @@ + 'Helios Alfa', 49 => 'Helios Metropolia']; + + public function setCinemaId($cinemaId) + { + $this->cinemaId = $cinemaId; + } + + public function setDay($day) + { + $this->day = $day; + } + + function fetchRepertorire() + { + 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; + } + + $documents = []; + foreach ($this->cinemaId as $cinema) { + $url = 'http://www.helios.pl/2,Gdansk/Repertuar/axRepertoire/?dzien=' . $this->day . '&kino=' . $cinema; + $data = json_decode(file_get_contents($url)); + + $document = new Document(); + $data->html = str_replace(["\n", "\t"], '', $data->html); + $document->loadHtml($data->html); + $documents[] = $document; + } + return $documents; + } + + 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()); + + $hours = []; + foreach ($seans->find('.time li') as $hour) { + $hours[] = $hour->text(); + } + $movie['hours'] = array_unique($hours); + $movies[] = $movie; + } + $cinemas[] = $movies; + } + return $cinemas; + } + + 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"; + } + return $text; + } +} \ No newline at end of file diff --git a/app/Paper/CinemaMultikino.php b/app/Paper/CinemaMultikino.php index 89b30a4..c0f7167 100644 --- a/app/Paper/CinemaMultikino.php +++ b/app/Paper/CinemaMultikino.php @@ -8,35 +8,47 @@ use App\Paper\Interfaces\Cinema; class CinemaMultikino implements Cinema { + private $cinemaId; + private $day; - function fetchRepertorire($day, $cinemaId = null) + public function setCinemaId($cinemaId) { - $moviePath = 'https://multikino.pl/data/filmswithshowings/' . $cinemaId; + $this->cinemaId = $cinemaId; + } + + public function setDay($day) + { + $this->day = $day; + } + + function fetchRepertorire() + { + + if (is_null($this->cinemaId) || is_null($this->day)) + throw new \Exception('Day or cinemaid not set.'); + $moviePath = 'https://multikino.pl/data/filmswithshowings/' . $this->cinemaId; $movieContent = file_get_contents($moviePath); - print_r($movieContent); $movieJson = json_decode($movieContent, 0); return $movieJson; } - function parseRepertoire($day, $cinemaId = null) + function parseRepertoire() { - $movieJson = $this->fetchRepertorire($day, $cinemaId); + $movieJson = $this->fetchRepertorire(); -echo $day; -// print_r($movieJson); $filmy = []; foreach ($movieJson->films as $movie) { $film = []; $film['id'] = $movie->id; $film['title'] = $movie->title; $film['times'] = []; - $film['date'] = $day; + $film['date'] = $this->day; $film['runningtime'] = $movie->info_runningtime; $film['genres'] = []; $film['synopsis_short'] = str_replace(["\r\n", " "], [" "], $movie->synopsis_short); if ($movie->original_s_count > 0 && $movie->show_showings) { foreach ($movie->showings as $shoving) { - if ($shoving->date_time == $day) { + if ($shoving->date_time == $this->day) { foreach ($shoving->times as $time) { $film['times'][] = $time->time . " " . $time->screen_type; } @@ -53,28 +65,27 @@ echo $day; } } -// print_r($filmy); - die(); return $filmy; } - function convertToPrint($day, $cinemaId = null) + function convertToPrint() { - $filmy = $this->parseRepertoire($day, $cinemaId); + $filmy = $this->parseRepertoire(); $text = ''; $text .= "Repertuar Multikino Gdańsk\n"; - $text .= $day . "\n\n"; + $text .= $this->day . "\n\n"; foreach ($filmy as $movie) { - $text .= $movie['title']. "\n"; - $text .= '('.$movie['runningtime']. ")\n"; + $text .= $movie['title'] . "\n"; + $text .= '(' . $movie['runningtime'] . ")\n"; $text .= implode(', ', $movie['genres']) . "\n\n"; $text .= $movie['synopsis_short'] . "\n\n"; $text .= implode(', ', $movie['times']) . "\n"; $text .= "--------------------------------\n\n"; } + return $text; } } \ No newline at end of file diff --git a/app/Paper/Interfaces/Cinema.php b/app/Paper/Interfaces/Cinema.php index 7f22b1b..6f2893f 100644 --- a/app/Paper/Interfaces/Cinema.php +++ b/app/Paper/Interfaces/Cinema.php @@ -11,10 +11,14 @@ namespace App\Paper\Interfaces; */ interface Cinema { - function fetchRepertorire($day, $cinemaId = null); + function setCinemaId($cinemaId); - function parseRepertoire($day, $cinemaId = null); + function setDay($day); - function convertToPrint($day, $cinemaId = null); + function fetchRepertorire(); + + function parseRepertoire(); + + function convertToPrint(); } \ No newline at end of file