Zionetrix::Git
Repositories
Help
Report an Issue
cinememe
Code
Commits
Branches
Tags
Search
Tree:
ee12681
Branches
Tags
master
cinememe
send.php
Add debug mode
Benjamin Renard
commited
ee12681
at 2015-01-07 10:06:21
send.php
Blame
History
Raw
<?php error_reporting(E_ERROR); @require_once "lib/api-allocine-helper/api-allocine-helper.php"; require_once "functions.php"; // Set locale to 'fr_FR.UTF-8' (required to retreive correct days short name) // CAUTION : If you want to modify it, you have to change day2int() function setlocale(LC_ALL, 'fr_FR.UTF-8'); // Manage script parameters $options=getopt('hDc:t:d:'); if (isset($options["h"])) { echo "Usage: ".$argv[0]." [-h] -c=[code_cine] -t=[0612345678] -d=[sms.domain.tld]\n"; echo " -h Show this message\n"; echo " -d Debug mode\n"; echo " -c=[code_cine] Specify cine code\n"; echo " -t=[number] Specify phone number\n"; echo " -d=[sms.domain.tld] Specify SMS mail domaine\n"; exit(); } $_debug=false; if (isset($options["D"])) { $_debug=true; } function debug($data,$dump=false) { global $_debug; if (!$_debug) return true; if ($dump) { var_dump($data); } else if (!is_array($data) && !is_object($data)) { echo "$data\n"; } return true; } debug("Options : ".print_r($options,1)); if (isset($options["c"]) && $options["c"]!==false) { $code_cine=$options["c"]; } else die("You must provide cine code with -c=XXX parameter.\n"); $send_to=false; $mail_domain=false; if (isset($options["t"]) && $options["t"]!==false) { $send_to=$options["t"]; if (isset($options["d"]) && $options["d"]!==false) { $mail_domain=$options["d"]; } else die("You must provide SMS mail domain with -d=domain.tld parameter.\n"); } try { $helper = new AlloHelper; debug("Request showtimes for cine $code_cine"); $result = $helper->showtimesByTheaters($code_cine); debug("Result :"); debug($result,true); } catch( ErrorException $error ) { die("Error retreiving informations (Err. n°". $error->getCode(). ") : ". $error->getMessage()); } try { debug("Parse result content..."); $name_cine=null; $movies=array(); foreach($result->theaterShowtimes as $t) { $name_cine=$t->place->theater->name; debug("Cine name : $name_cine"); foreach($t->movieShowtimes as $mst) { $movie=utf8_encode($mst->onShow->movie->title); $suf=array(); if ($mst->screenFormat['$']=='3D') { $suf[]='3D'; } if ($mst->version->code!=6001) { $suf[]='VO'; } if(count($suf)>0) { $movie.=' ('.implode('/',$suf).')'; } if (!isset($movies[$movie])) { debug("New movie : $movie"); $movies[$movie]=array(); } foreach($mst->scr as $day) { $date=DateTime::createFromFormat('Y-m-d',$day['d']); $jour=str_replace('.','',strftime('%a',$date->getTimestamp())); if(!isset($movies[$movie][$jour])) $movies[$movie][$jour]=array(); foreach($day['t'] as $t) { debug("New schedule time for movie $movie : day=$jour / time=".$t['$']); $movies[$movie][$jour][]=$t['$']; } } } } } catch( ErrorException $error ) { die("Error parsing informations (Err. n°".$error->getCode().") : ".$error->getMessage()); } debug("Parsing result :".print_r($movies,1)); // Format movies informations $fmovies=group_days($movies); debug("Formated movies informations : ".print_r($fmovies,1)); // Calculate start/end of cine week $start_date=new Datetime(date('Y-m-d').' 00:00:00'); $start=$start_date->format('d/m'); $start_time=$start_date->getTimestamp(); $start_wd=(int)date('N',$start_time); $end_time=$start_time+(24*3600*((9-$start_wd)%7)); $end=date('d/m',$end_time); // Format Message $msg="Cinema $name_cine\nProgramme du $start au $end\n"; foreach($fmovies as $m => $ps){ $msg.="$m : "; $hss=array(); foreach($ps as $p => $hs) { $hss[]="$p ".implode(' & ',$hs); } $msg.=implode(' / ',$hss)."\n"; } // Remove accents $msg=$msg=withoutAccents($msg); if ($send_to && $mail_domain) { // Format mail $mail="$send_to@$mail_domain"; // Display message echo "Send to $mail :\n\n$msg"; // Send message mail($mail,'',$msg); } else { echo "$msg"; }