Added Gdynskie centrum filmowe to cinemas.

This commit is contained in:
kplaczek
2018-04-14 12:40:56 +02:00
parent 42801c93e9
commit 56b656d1e7
2 changed files with 91 additions and 41 deletions

View File

@@ -3,9 +3,9 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Paper\CinemaCinemaCity; use App\Paper\CinemaCinemaCity;
use App\Paper\CinemaGdynskieCentrumFilmowe;
use App\Paper\CinemaHelios; use App\Paper\CinemaHelios;
use App\Paper\CinemaMultikino; use App\Paper\CinemaMultikino;
use DiDom\Document;
use App\Paper\Paper; use App\Paper\Paper;
class Repertoire extends Controller class Repertoire extends Controller
@@ -22,7 +22,6 @@ class Repertoire extends Controller
public function today_cinemacity() public function today_cinemacity()
{ {
$cinemacity = new CinemaCinemaCity(); $cinemacity = new CinemaCinemaCity();
$cinemacity->setCinemaId(1010912); $cinemacity->setCinemaId(1010912);
$cinemacity->setDay(date('Y-m-d')); $cinemacity->setDay(date('Y-m-d'));
@@ -30,7 +29,6 @@ class Repertoire extends Controller
$this->main->sendPrint('', $repertuarText, $this->icon); $this->main->sendPrint('', $repertuarText, $this->icon);
return back(); return back();
} }
@@ -43,8 +41,6 @@ class Repertoire extends Controller
$this->main->sendPrint('', $repertuarText, $this->icon); $this->main->sendPrint('', $repertuarText, $this->icon);
return back(); return back();
} }
@@ -62,7 +58,6 @@ class Repertoire extends Controller
public function tomorrow_multikino() public function tomorrow_multikino()
{ {
$multikino = new CinemaMultikino(); $multikino = new CinemaMultikino();
$multikino->setDay(date_create()->modify('+1 day')->format('Y-m-d')); $multikino->setDay(date_create()->modify('+1 day')->format('Y-m-d'));
$multikino->setCinemaId(4); $multikino->setCinemaId(4);
@@ -75,25 +70,26 @@ class Repertoire extends Controller
public function tomorrow_gdynskiecentrumfilmowe() public function tomorrow_gdynskiecentrumfilmowe()
{ {
$date = new \DateTime(); $gdynskieCentrumFilmowe = new CinemaGdynskieCentrumFilmowe();
$date->modify('+1 day'); $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(); return back();
} }
public function today_gdynskiecentrumfilmowe() public function today_gdynskiecentrumfilmowe()
{ {
$date = date('d_m_Y'); $gdynskieCentrumFilmowe = new CinemaGdynskieCentrumFilmowe();
$repertuarText = $this->gdynskieCentrumFilmowe($date); $gdynskieCentrumFilmowe->setDay(date('d_m_y'));
$repertuarText = $gdynskieCentrumFilmowe->convertToPrint();
$this->main->sendPrint('', $repertuarText, $this->icon); $this->main->sendPrint('', $repertuarText, $this->icon);
return back(); return back();
} }
public function today_helios() public function today_helios()
{ {
$helios = new CinemaHelios(); $helios = new CinemaHelios();
$helios->setDay(0); $helios->setDay(0);
$helios->setCinemaId([2, 49]); $helios->setCinemaId([2, 49]);
@@ -120,46 +116,18 @@ class Repertoire extends Controller
public function today_repertoire() public function today_repertoire()
{ {
$this->today_multikino(); $this->today_multikino();
$this->today_cinemacity(); $this->today_cinemacity();
$this->today_helios(); $this->today_helios();
$this->today_gdynskiecentrumfilmowe(); $this->today_gdynskiecentrumfilmowe();
} }
public function tomorrow_repertoire() public function tomorrow_repertoire()
{ {
$this->tomorrow_multikino(); $this->tomorrow_multikino();
$this->tomorrow_cinemacity(); $this->tomorrow_cinemacity();
$this->tomorrow_helios(); $this->tomorrow_helios();
$this->tomorrow_gdynskiecentrumfilmowe(); $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;
}
} }

View File

@@ -0,0 +1,82 @@
<?php
namespace App\Paper;
use App\Paper\Interfaces\Cinema;
use DiDom\Document;
class CinemaGdynskieCentrumFilmowe implements Cinema
{
private $cinemaId;
private $day;
public function setCinemaId($cinemaId)
{
$this->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;
}
}