Refactored CinemaCity repertoire fetcher.
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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