Ejemplo n.º 1
0
 /**
  * @param string $date date in yyyy-mm-dd form
  * @param string $time time in HH:MM form
  * @param int $offset in minutes
  * @return \DateTime
  */
 private function getDateTime($date, $time, $offset = 0)
 {
     $dateTime = new \DateTime("{$date} {$time}", $this->dateTimeZone);
     if ($offset) {
         $subtract = $offset < 0;
         $interval = new \DateInterval('PT' . abs($offset) . 'M');
         $dateTime = $subtract ? $dateTime->sub($interval) : $dateTime->add($interval);
     }
     \SystemLogger::info('Time: Generated', $date, $time, $dateTime->format('c'));
     return $dateTime;
 }
Ejemplo n.º 2
0
 protected function extractShowtimes($pageData)
 {
     $startTime = microtime(true);
     \SystemLogger::debug('Extraction of page started, total length = ', strlen($pageData));
     \SystemLogger::debug('Loading into QueryPath');
     $imdbPage = QueryPath::withHTML($pageData);
     \SystemLogger::debug('Query Path done loading...');
     \SystemLogger::debug(__CLASS__, "Extracting theatres...");
     //$cinemasList = $imdbPage->find("#cinemas-at-list .list_item.odd, #cinemas-at-list .list_item.even");
     $cinemasList = $imdbPage->find("#cinemas-at-list > .list_item");
     \SystemLogger::debug(__CLASS__, "Found: ", $cinemasList->count(), "cinemas");
     $theatreMovieShowtimes = array();
     if ($cinemasList) {
         for ($i = 0; $i < ShowtimeService::THEATRE_LIMIT && $i < $cinemasList->count(); $i++) {
             \SystemLogger::debug('Processing theatre at position: ', $i);
             /* @var $cinemaDiv DOMQuery */
             $cinemaDiv = new DOMQuery($cinemasList->get($i));
             $theatreData = array();
             $theatreTitle = $cinemaDiv->find('h3')->first();
             \SystemLogger::info("{$i}. Theatre: ", $theatreTitle->text());
             if (!$theatreTitle) {
                 \SystemLogger::debug(__CLASS__, "No theatre found");
                 continue;
             }
             $theatreData['name'] = trim($theatreTitle->text());
             $addressSpanTmp = $cinemaDiv->find('.address div');
             $addressSpan = $addressSpanTmp ? preg_replace('/\\s+/', ' ', $addressSpanTmp->text()) : "";
             $theatreData['address'] = trim(explode('|', $addressSpan)[0]);
             $movieDomList = $cinemaDiv->find('.list_item');
             \SystemLogger::info(__CLASS__, "Number of Movies = ", $movieDomList->count());
             if (!count($movieDomList)) {
                 \SystemLogger::debug(__CLASS__, "No movies found");
                 continue;
             }
             $theatreMovieShowtimes[] = array('theatre' => $theatreData, 'movies' => $this->extractMovies($movieDomList));
             \SystemLogger::debug('--Theatre extraction completed---');
         }
     }
     \SystemLogger::debug('Showtimes extraction completed in :', microtime(true) - $startTime);
     //var_dump($theatreMovieShowtimes);exit;
     return $theatreMovieShowtimes;
 }
 /**
  * @param Theatre $theatre
  * @return bool|mixed|\mysqli_result
  */
 public static function setTheatreLatLng(Theatre $theatre)
 {
     //51.4752267,-0.2396438
     \SystemLogger::info("Finding LongLat for: ", $theatre->name, $theatre->address);
     $geocode = LocationService::instance()->addressLookup($theatre->address, [], true);
     $saved = false;
     if ($geocode) {
         $geoLocation = $geocode->getGeocode();
         \SystemLogger::info("Found Geocode: ", strval($geoLocation));
         $saved = $theatre->update(['longitude' => $geoLocation->getLongitude(), 'latitude' => $geoLocation->getLatitude()], 'id');
     }
     return $saved;
 }
 public static function cleanPbis()
 {
     $staleDate = strtotime("-4 days");
     $files = glob(CACHE_DIR . "/*");
     $removed = 0;
     foreach ($files as $file) {
         \SystemLogger::info("Looking at: ", $file);
         if (filemtime($file) < $staleDate && unlink($file)) {
             \SystemLogger::info("\tRemoved file: ", $file);
             $removed++;
         }
     }
     return $removed;
 }
Ejemplo n.º 5
0
 private function extractTheatreMovieShowtimes($pageData, $limit, &$totalPages)
 {
     $startTime = microtime(true);
     \SystemLogger::debug("Begining extraction of data from file, size = ", strlen($pageData));
     if ($limit <= 0) {
         \SystemLogger::warn("Invalid limit was supplied: ", $limit);
         return array();
     }
     \SystemLogger::debug('Attempting to load into Query Path');
     /* @var $moviePage DOMQuery */
     $moviePage = \QueryPath::withHTML($pageData, null, array('convert_to_encoding' => "UTF-8", 'convert_from_encoding' => "UTF-8"));
     \SystemLogger::debug('Loaded into QueryPath');
     /* @var $theatersDom DOMQuery */
     $theatersDom = $moviePage->find("div.theater");
     //get total pages
     $paginationDom = $moviePage->find("#navbar td");
     $totalPages = $paginationDom->length ? $paginationDom->length - 2 : 1;
     \SystemLogger::debug("Found", $theatersDom->length, "theatres");
     $theatreCinemas = array();
     $foundTheatres = 0;
     \SystemLogger::debug('Loading data from Theatres DOM list');
     for ($i = 0; $i < $theatersDom->length && $foundTheatres < $limit; $i++) {
         $theatre = array();
         $theatreDom = new DOMQuery($theatersDom->get($i));
         $theatre['name'] = trim($theatreDom->find("h2.name")->first()->text());
         if (!$theatre['name']) {
             \SystemLogger::warn("Found no theatre at dom level: ", $i);
             continue;
         }
         \SystemLogger::debug("processing theatre: ", $theatre['name']);
         $addressText = $theatreDom->find(".info")->first()->text();
         //echo  $addressText, "<br>";
         $tmp = explode(" - ", trim($addressText));
         array_pop($tmp);
         $theatre['address'] = join(' ', $tmp);
         $theatreCinemas[] = array('theatre' => $theatre, 'movies' => $this->extractMovieShowtimes($theatreDom));
         $foundTheatres++;
     }
     \SystemLogger::info('Extraction done, completed in ', microtime(true) - $startTime, 'ms');
     return $theatreCinemas;
 }
 public function doPreload()
 {
     $version = $this->currentVersion;
     if ($this->geocode) {
         $status = $this->showtimeService->loadData($this->geocode, $this->currentDate, false, $this->dateOffset);
         \SystemLogger::info("PreloadStatus: ", $status);
     }
     $this->result['status'] = $status;
     $this->result['version'] = $version;
 }