Refactored CinemaCity repertoire fetcher.

This commit is contained in:
kplaczek
2018-04-09 22:56:51 +02:00
parent 60611015e5
commit 42801c93e9
2 changed files with 56 additions and 96 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Paper\CinemaCinemaCity;
use App\Paper\CinemaHelios; use App\Paper\CinemaHelios;
use App\Paper\CinemaMultikino; use App\Paper\CinemaMultikino;
use DiDom\Document; use DiDom\Document;
@@ -21,65 +22,31 @@ class Repertoire extends Controller
public function today_cinemacity() public function today_cinemacity()
{ {
$date = date('d/m/Y');
$repertuarText = $this->cinemacityRepertuar($date); $cinemacity = new CinemaCinemaCity();
// $this->main->sendPrint('', $repertuarText, $this->icon, $this->icon); $cinemacity->setCinemaId(1010912);
$cinemacity->setDay(date('Y-m-d'));
$repertuarText = $cinemacity->convertToPrint();
$this->main->sendPrint('', $repertuarText, $this->icon);
return back(); return back();
} }
public function tomorrow_cinemacity() public function tomorrow_cinemacity()
{ {
$date = new \DateTime(); $cinemacity = new CinemaCinemaCity();
$date->modify('+1 day'); $cinemacity->setCinemaId(1010912);
$repertuarText = $this->cinemacityRepertuar($date->format('d/m/Y')); $cinemacity->setDay(date_create()->modify('+1 day')->format('Y-m-d'));
// $this->main->sendPrint('', $repertuarText, $this->icon, $this->icon); $repertuarText = $cinemacity->convertToPrint();
$this->main->sendPrint('', $repertuarText, $this->icon);
return back(); 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() public function today_multikino()
{ {

View File

@@ -26,69 +26,62 @@ class CinemaCinemaCity implements Cinema
if (is_null($this->cinemaId) || is_null($this->day)) if (is_null($this->cinemaId) || is_null($this->day))
throw new \Exception('Day or cinemaid not set.'); throw new \Exception('Day or cinemaid not set.');
if (!is_array($this->cinemaId)) { // if (!is_array($this->cinemaId)) {
$this->cinemaId = (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;
$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;
return file_get_contents($url);
} }
function parseRepertoire() function parseRepertoire()
{ {
$documents = $this->fetchRepertorire(); $document = $this->fetchRepertorire();
$cinemas = []; $document = json_decode($document);
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) { // $cinemaData = [];
$hours[] = $hour->text(); // $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; $movies[] = $movie;
} }
$cinemas[] = $movies;
} }
return $cinemas;
return $movies;
} }
function convertToPrint() function convertToPrint()
{ {
$cinemas = $this->parseRepertoire(); $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 = "Repertuar Cinema-City\n";
$text .= $film['title'] . "\n"; $text .= $this->day . "\n\n";
$text .= implode(', ', array_unique($film['hours'])) . "\n\n";
} foreach ($cinemas as $movie) {
$text .= "\n"; $text .= $movie['title'] . "\n";
$text .= implode(',', $movie['hours'] ). "\n\n";
} }
return $text; return $text;
} }