Updated helios and multikino classes and interface they are implementing.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Paper\CinemaHelios;
|
||||||
use App\Paper\CinemaMultikino;
|
use App\Paper\CinemaMultikino;
|
||||||
use DiDom\Document;
|
use DiDom\Document;
|
||||||
use App\Paper\Paper;
|
use App\Paper\Paper;
|
||||||
@@ -10,7 +11,7 @@ class Repertoire extends Controller
|
|||||||
{
|
{
|
||||||
|
|
||||||
private $main;
|
private $main;
|
||||||
private $icon = '/small/film.png';
|
private $icon = 'film';
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
@@ -22,7 +23,7 @@ class Repertoire extends Controller
|
|||||||
{
|
{
|
||||||
$date = date('d/m/Y');
|
$date = date('d/m/Y');
|
||||||
$repertuarText = $this->cinemacityRepertuar($date);
|
$repertuarText = $this->cinemacityRepertuar($date);
|
||||||
$this->main->sendPrint('', $repertuarText, $this->icon, $this->icon);
|
// $this->main->sendPrint('', $repertuarText, $this->icon, $this->icon);
|
||||||
return back();
|
return back();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ class Repertoire extends Controller
|
|||||||
$date = new \DateTime();
|
$date = new \DateTime();
|
||||||
$date->modify('+1 day');
|
$date->modify('+1 day');
|
||||||
$repertuarText = $this->cinemacityRepertuar($date->format('d/m/Y'));
|
$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();
|
return back();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,51 +59,50 @@ class Repertoire extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function multikinoRepertuar($date)
|
// private function multikinoRepertuar($date)
|
||||||
{
|
// {
|
||||||
|
//
|
||||||
$text = '';
|
// $text = '';
|
||||||
$repertuar = json_decode(file_get_contents('https://multikino.pl/pl/repertoire/cinema/seances?id=4&from=' . $date));
|
// $repertuar = json_decode(file_get_contents('https://multikino.pl/pl/repertoire/cinema/seances?id=4&from=' . $date));
|
||||||
$text .= "Repertuar Multikino Gdańsk\n";
|
// $text .= "Repertuar Multikino Gdańsk\n";
|
||||||
$text .= $date . "\n\n";
|
// $text .= $date . "\n\n";
|
||||||
|
//
|
||||||
foreach ($repertuar->results as $movie) {
|
// foreach ($repertuar->results as $movie) {
|
||||||
$text .= $movie->title . "\n";
|
// $text .= $movie->title . "\n";
|
||||||
$text .= $movie->print_version . "\n";
|
// $text .= $movie->print_version . "\n";
|
||||||
|
//
|
||||||
$hours = [];
|
// $hours = [];
|
||||||
foreach ($movie->seances as $seans) {
|
// foreach ($movie->seances as $seans) {
|
||||||
$hours[] = date('H:i', strtotime($seans->beginning_date));
|
// $hours[] = date('H:i', strtotime($seans->beginning_date));
|
||||||
}
|
// }
|
||||||
$text .= implode(', ', $hours) . "\n\n";
|
// $text .= implode(', ', $hours) . "\n\n";
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return $text;
|
// return $text;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public function today_multikino()
|
public function today_multikino()
|
||||||
{
|
{
|
||||||
$multikino = new CinemaMultikino();
|
$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);
|
$this->main->sendPrint('', $repertuarText, $this->icon);
|
||||||
return back();
|
return back();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tomorrow_multikino()
|
public function tomorrow_multikino()
|
||||||
{
|
{
|
||||||
$date = new \DateTime();
|
|
||||||
$date->modify('+1 day');
|
|
||||||
|
|
||||||
$multikino = new CinemaMultikino();
|
$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);
|
$this->main->sendPrint('', $repertuarText, $this->icon);
|
||||||
return back();
|
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');
|
$date->modify('+1 day');
|
||||||
|
|
||||||
$repertuarText = $this->gdynskieCentrumFilmowe($date->format('d_m_Y'));
|
$repertuarText = $this->gdynskieCentrumFilmowe($date->format('d_m_Y'));
|
||||||
$this->main->sendPrint('', $repertuarText, $this->icon);
|
// $this->main->sendPrint('', $repertuarText, $this->icon);
|
||||||
return back();
|
return back();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,15 +126,28 @@ class Repertoire extends Controller
|
|||||||
|
|
||||||
public function today_helios()
|
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();
|
return back();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tomorrow_helios()
|
public function tomorrow_helios()
|
||||||
{
|
{
|
||||||
$this->main->sendPrint('', $this->helios(1, 2), $this->icon);
|
$helios = new CinemaHelios();
|
||||||
$this->main->sendPrint('', $this->helios(1, 49));
|
$helios->setDay(1);
|
||||||
|
$helios->setCinemaId([2, 49]);
|
||||||
|
$helios->convertToPrint();
|
||||||
|
|
||||||
|
$repertuarText = $helios->convertToPrint();
|
||||||
|
$this->main->sendPrint('', $repertuarText, $this->icon);
|
||||||
|
|
||||||
return back();
|
return back();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,40 +170,6 @@ class Repertoire extends Controller
|
|||||||
$this->tomorrow_gdynskiecentrumfilmowe();
|
$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)
|
private function gdynskieCentrumFilmowe($date)
|
||||||
{
|
{
|
||||||
|
|||||||
86
app/Paper/CinemaHelios.php
Normal file
86
app/Paper/CinemaHelios.php
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Paper;
|
||||||
|
|
||||||
|
use App\Paper\Interfaces\Cinema;
|
||||||
|
use DiDom\Document;
|
||||||
|
|
||||||
|
class CinemaHelios implements Cinema
|
||||||
|
{
|
||||||
|
|
||||||
|
private $cinemaId;
|
||||||
|
private $day;
|
||||||
|
|
||||||
|
private $cinemas = [2 => '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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,35 +8,47 @@ use App\Paper\Interfaces\Cinema;
|
|||||||
class CinemaMultikino implements 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);
|
$movieContent = file_get_contents($moviePath);
|
||||||
print_r($movieContent);
|
|
||||||
$movieJson = json_decode($movieContent, 0);
|
$movieJson = json_decode($movieContent, 0);
|
||||||
return $movieJson;
|
return $movieJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseRepertoire($day, $cinemaId = null)
|
function parseRepertoire()
|
||||||
{
|
{
|
||||||
$movieJson = $this->fetchRepertorire($day, $cinemaId);
|
$movieJson = $this->fetchRepertorire();
|
||||||
|
|
||||||
echo $day;
|
|
||||||
// print_r($movieJson);
|
|
||||||
$filmy = [];
|
$filmy = [];
|
||||||
foreach ($movieJson->films as $movie) {
|
foreach ($movieJson->films as $movie) {
|
||||||
$film = [];
|
$film = [];
|
||||||
$film['id'] = $movie->id;
|
$film['id'] = $movie->id;
|
||||||
$film['title'] = $movie->title;
|
$film['title'] = $movie->title;
|
||||||
$film['times'] = [];
|
$film['times'] = [];
|
||||||
$film['date'] = $day;
|
$film['date'] = $this->day;
|
||||||
$film['runningtime'] = $movie->info_runningtime;
|
$film['runningtime'] = $movie->info_runningtime;
|
||||||
$film['genres'] = [];
|
$film['genres'] = [];
|
||||||
$film['synopsis_short'] = str_replace(["\r\n", " "], [" "], $movie->synopsis_short);
|
$film['synopsis_short'] = str_replace(["\r\n", " "], [" "], $movie->synopsis_short);
|
||||||
if ($movie->original_s_count > 0 && $movie->show_showings) {
|
if ($movie->original_s_count > 0 && $movie->show_showings) {
|
||||||
foreach ($movie->showings as $shoving) {
|
foreach ($movie->showings as $shoving) {
|
||||||
if ($shoving->date_time == $day) {
|
if ($shoving->date_time == $this->day) {
|
||||||
foreach ($shoving->times as $time) {
|
foreach ($shoving->times as $time) {
|
||||||
$film['times'][] = $time->time . " " . $time->screen_type;
|
$film['times'][] = $time->time . " " . $time->screen_type;
|
||||||
}
|
}
|
||||||
@@ -53,18 +65,16 @@ echo $day;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// print_r($filmy);
|
|
||||||
die();
|
|
||||||
return $filmy;
|
return $filmy;
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertToPrint($day, $cinemaId = null)
|
function convertToPrint()
|
||||||
{
|
{
|
||||||
$filmy = $this->parseRepertoire($day, $cinemaId);
|
$filmy = $this->parseRepertoire();
|
||||||
|
|
||||||
$text = '';
|
$text = '';
|
||||||
$text .= "Repertuar Multikino Gdańsk\n";
|
$text .= "Repertuar Multikino Gdańsk\n";
|
||||||
$text .= $day . "\n\n";
|
$text .= $this->day . "\n\n";
|
||||||
|
|
||||||
foreach ($filmy as $movie) {
|
foreach ($filmy as $movie) {
|
||||||
$text .= $movie['title'] . "\n";
|
$text .= $movie['title'] . "\n";
|
||||||
@@ -75,6 +85,7 @@ echo $day;
|
|||||||
$text .= implode(', ', $movie['times']) . "\n";
|
$text .= implode(', ', $movie['times']) . "\n";
|
||||||
$text .= "--------------------------------\n\n";
|
$text .= "--------------------------------\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,10 +11,14 @@ namespace App\Paper\Interfaces;
|
|||||||
*/
|
*/
|
||||||
interface Cinema
|
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();
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user