Merge remote-tracking branch 'origin/master' into issue-7

This commit is contained in:
kplaczek
2018-04-15 14:35:46 +02:00
147 changed files with 337 additions and 57155 deletions

View File

@@ -0,0 +1,88 @@
<?php
namespace App\Paper;
use App\Paper\Interfaces\Cinema;
use DiDom\Document;
class CinemaCinemaCity 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->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/pgm-list-byfeat?si=' . $this->cinemaId . '&sort=cin&bd=' . $this->day;
return file_get_contents($url);
}
function parseRepertoire()
{
$document = $this->fetchRepertorire();
$document = json_decode($document);
// $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;
}
}
}
if (count($movie['hours']) > 0) {
$movies[] = $movie;
}
}
return $movies;
}
function convertToPrint()
{
$cinemas = $this->parseRepertoire();
$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;
}
}

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;
}
}

View 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;
}
}

View File

@@ -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;
}
}

View File

@@ -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();
}