Commit 67f63be1 authored by Michał Gurbiel's avatar Michał Gurbiel

Add Cinema 3D chain download and convert (Cinema3dTimetableMaker class)

parent fb59c109
Pipeline #54041125 passed with stages
in 8 minutes and 26 seconds
## About
This is a command-line script for downloading and processing movie screenings data from 3 major cinema chains in Poland (Cinema City, Multikino and Helios), intended as data source for "Cinema Citizen" web application ([website](http://cctzn.leibrug.pl) | [repository](https://gitlab.com/cctzn/app)).
This is a command-line script for downloading and processing movie screenings data from 4 major cinema chains in Poland (Cinema City, Multikino, Helios and Cinema 3D), intended as data source for "Cinema Citizen" web application ([website](http://cctzn.leibrug.pl) | [repository](https://gitlab.com/cctzn/app)).
## Usage
......
......@@ -13,14 +13,14 @@ $getopt = new \GetOpt\GetOpt([
\GetOpt\Option::create(null, 'chains', \GetOpt\GetOpt::REQUIRED_ARGUMENT)
->setDescription(
'Cinema chains to process as comma-separated chain IDs [cc|mk|h]; ' .
'Cinema chains to process as comma-separated chain IDs [cc|mk|h|c3d]; ' .
'by default process all chains'
)
->setArgumentName('chains')
->setDefaultValue('cc,mk,h')
->setDefaultValue('cc,mk,h,c3d')
->setValidation(function($value) {
foreach(explode(',', $value) as $chain) {
if (!in_array($chain, ['cc', 'mk', 'h'])) {
if (!in_array($chain, ['cc', 'mk', 'h', 'c3d'])) {
return false;
}
}
......@@ -82,6 +82,13 @@ $getopt = new \GetOpt\GetOpt([
)
->setArgumentName('cinemas'),
\GetOpt\Option::create(null, 'cinemas-c3d', \GetOpt\GetOpt::OPTIONAL_ARGUMENT)
->setDescription(
'Cinema 3D cinema IDs to process as comma-separated cinema IDs; ' .
'by default process all cinemas'
)
->setArgumentName('cinemas'),
]);
$getopt->process();
......@@ -119,3 +126,9 @@ if (in_array('h', $chains)) {
$heliosTimetableMaker->setCinemas($getopt->getOption('cinemas-h'));
$heliosTimetableMaker->makeTimetables();
}
if (in_array('c3d', $chains)) {
$cinema3dTimetableMaker = new Cinema3dTimetableMaker;
$cinema3dTimetableMaker->setCinemas($getopt->getOption('cinemas-c3d'));
$cinema3dTimetableMaker->makeTimetables();
}
<?php
class Cinema3dTimetableMaker extends TimetableMaker {
protected $CINEMAS = [
'biala-podlaska',
'gdansk',
'glogow',
'gorzow-wlkp',
'kalisz',
'klodzko',
'leszno',
'mielec',
'swidnica',
'swinoujscie',
'tarnow',
];
const RAW_FILE_NAME = 'c3d_%s_%s.raw';
const DOWNLOAD_URL = 'http://system.v67926.tld.pl/api/v1/seances/%s/%s';
const DATA_FILE_NAME = 'c3d_%s_%s.json';
protected function download() {
foreach ($this->CINEMAS as $cinema) {
foreach (self::$DAYS as $day) {
$rawFileName = sprintf(self::RAW_FILE_NAME, $cinema, date('Ymd', $day));
$curlOpts = [
CURLOPT_URL => sprintf(self::DOWNLOAD_URL, $cinema, date('Y-m-d', $day)),
];
self::getRawFile($rawFileName, $curlOpts);
}
}
}
protected function convert() {
foreach ($this->CINEMAS as $cinema) {
foreach (self::$DAYS as $day) {
$rawFilePath = self::$OPTIONS['raw_dir'] . '/' . sprintf(self::RAW_FILE_NAME, $cinema, date('Ymd', $day));
$rawData = json_decode(file_get_contents($rawFilePath));
$data = [];
foreach ($rawData as $film) {
// TODO: if not $film->movie, this looks like a single special screening
// - find out how to handle (it can have 'null' duration)
if (isset($film->movie)) {
$result = [
'title' => $film->movie->title,
'duration' => $film->movie->duration * 60,
'labels' => [], // TODO: labels
'hours' => array_values(array_map(
function($seance) {
return strtotime($seance->start);
},
$film->seances
)),
];
array_push($data, $result);
}
}
$dataFileName = sprintf(self::DATA_FILE_NAME, $cinema, date('Ymd', $day));
self::saveDataFile($dataFileName, $data);
}
}
}
}
......@@ -60,7 +60,7 @@ class TimetableMaker {
public function setCinemas($cinemas) {
if (!is_null($cinemas)) {
$this->CINEMAS = array_map('intval', explode(',', $cinemas));
$this->CINEMAS = explode(',', $cinemas);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment