From d68020d0567aa214dbc4a1a204692f9001961689 Mon Sep 17 00:00:00 2001 From: kplaczek Date: Thu, 5 Apr 2018 22:38:20 +0200 Subject: [PATCH 1/4] Updated helios and multikino classes and interface they are implementing. --- app/Http/Controllers/Repertoire.php | 123 ++++++++++++---------------- app/Paper/CinemaHelios.php | 86 +++++++++++++++++++ app/Paper/CinemaMultikino.php | 43 ++++++---- app/Paper/Interfaces/Cinema.php | 10 ++- 4 files changed, 171 insertions(+), 91 deletions(-) create mode 100644 app/Paper/CinemaHelios.php diff --git a/app/Http/Controllers/Repertoire.php b/app/Http/Controllers/Repertoire.php index 98dbf5d..038ef82 100644 --- a/app/Http/Controllers/Repertoire.php +++ b/app/Http/Controllers/Repertoire.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Paper\CinemaHelios; use App\Paper\CinemaMultikino; use DiDom\Document; use App\Paper\Paper; @@ -10,7 +11,7 @@ class Repertoire extends Controller { private $main; - private $icon = '/small/film.png'; + private $icon = 'film'; public function __construct() { @@ -22,7 +23,7 @@ class Repertoire extends Controller { $date = date('d/m/Y'); $repertuarText = $this->cinemacityRepertuar($date); - $this->main->sendPrint('', $repertuarText, $this->icon, $this->icon); +// $this->main->sendPrint('', $repertuarText, $this->icon, $this->icon); return back(); } @@ -32,7 +33,7 @@ class Repertoire extends Controller $date = new \DateTime(); $date->modify('+1 day'); $repertuarText = $this->cinemacityRepertuar($date->format('d/m/Y')); - $this->main->sendPrint('', $repertuarText, $this->icon, $this->icon); +// $this->main->sendPrint('', $repertuarText, $this->icon, $this->icon); return back(); } @@ -58,51 +59,50 @@ class Repertoire extends Controller } - 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; - } +// 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(); } @@ -112,7 +112,7 @@ class Repertoire extends Controller $date->modify('+1 day'); $repertuarText = $this->gdynskieCentrumFilmowe($date->format('d_m_Y')); - $this->main->sendPrint('', $repertuarText, $this->icon); +// $this->main->sendPrint('', $repertuarText, $this->icon); return back(); } @@ -126,15 +126,28 @@ class Repertoire extends Controller 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(); } @@ -157,40 +170,6 @@ class Repertoire extends Controller $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) { 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 From 60611015e526363e63a76fc72bcb9c55b52191e5 Mon Sep 17 00:00:00 2001 From: kplaczek Date: Sat, 7 Apr 2018 20:30:18 +0200 Subject: [PATCH 2/4] Cinema City class added. Need some extra work though. --- app/Paper/CinemaCinemaCity.php | 95 ++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 app/Paper/CinemaCinemaCity.php diff --git a/app/Paper/CinemaCinemaCity.php b/app/Paper/CinemaCinemaCity.php new file mode 100644 index 0000000..7e4507a --- /dev/null +++ b/app/Paper/CinemaCinemaCity.php @@ -0,0 +1,95 @@ +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/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; + + + } + + 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 From 42801c93e91cc8bc8754eae21b7fb69f98b3501e Mon Sep 17 00:00:00 2001 From: kplaczek Date: Mon, 9 Apr 2018 22:56:51 +0200 Subject: [PATCH 3/4] Refactored CinemaCity repertoire fetcher. --- app/Http/Controllers/Repertoire.php | 67 ++++++----------------- app/Paper/CinemaCinemaCity.php | 85 +++++++++++++---------------- 2 files changed, 56 insertions(+), 96 deletions(-) diff --git a/app/Http/Controllers/Repertoire.php b/app/Http/Controllers/Repertoire.php index 038ef82..cf58f05 100644 --- a/app/Http/Controllers/Repertoire.php +++ b/app/Http/Controllers/Repertoire.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Paper\CinemaCinemaCity; use App\Paper\CinemaHelios; use App\Paper\CinemaMultikino; use DiDom\Document; @@ -21,65 +22,31 @@ 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() { diff --git a/app/Paper/CinemaCinemaCity.php b/app/Paper/CinemaCinemaCity.php index 7e4507a..4e23d9c 100644 --- a/app/Paper/CinemaCinemaCity.php +++ b/app/Paper/CinemaCinemaCity.php @@ -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; } From 56b656d1e70b6ec5202462459aa572659ed0e739 Mon Sep 17 00:00:00 2001 From: kplaczek Date: Sat, 14 Apr 2018 12:40:56 +0200 Subject: [PATCH 4/4] Added Gdynskie centrum filmowe to cinemas. --- app/Http/Controllers/Repertoire.php | 50 +++---------- app/Paper/CinemaGdynskieCentrumFilmowe.php | 82 ++++++++++++++++++++++ 2 files changed, 91 insertions(+), 41 deletions(-) create mode 100644 app/Paper/CinemaGdynskieCentrumFilmowe.php diff --git a/app/Http/Controllers/Repertoire.php b/app/Http/Controllers/Repertoire.php index cf58f05..4508ecc 100644 --- a/app/Http/Controllers/Repertoire.php +++ b/app/Http/Controllers/Repertoire.php @@ -3,9 +3,9 @@ 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 @@ -22,7 +22,6 @@ class Repertoire extends Controller public function today_cinemacity() { - $cinemacity = new CinemaCinemaCity(); $cinemacity->setCinemaId(1010912); $cinemacity->setDay(date('Y-m-d')); @@ -30,7 +29,6 @@ class Repertoire extends Controller $this->main->sendPrint('', $repertuarText, $this->icon); return back(); - } @@ -43,8 +41,6 @@ class Repertoire extends Controller $this->main->sendPrint('', $repertuarText, $this->icon); return back(); - - } @@ -62,7 +58,6 @@ class Repertoire extends Controller public function tomorrow_multikino() { - $multikino = new CinemaMultikino(); $multikino->setDay(date_create()->modify('+1 day')->format('Y-m-d')); $multikino->setCinemaId(4); @@ -75,25 +70,26 @@ class Repertoire extends Controller 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); + $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() { - $helios = new CinemaHelios(); $helios->setDay(0); $helios->setCinemaId([2, 49]); @@ -120,46 +116,18 @@ class Repertoire extends Controller 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 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/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