Initial commit
Benjamin Renard authored 10 years ago
|
1) <?php
2)
3) error_reporting(E_ERROR);
4)
5) @require_once "lib/api-allocine-helper/api-allocine-helper.php";
6) require_once "functions.php";
7)
8) // Retreive local from environnement
9) setlocale(LC_ALL, '');
10)
11) // Manage script parameters
12) $options=getopt('hc:t:d:');
13)
14) if (isset($options["h"])) {
15) echo "Usage: ".$argv[0]." [-h] -c=[code_cine] -t=[0612345678] -d=[sms.domain.tld]\n";
16) echo " -h Show this message\n";
17) echo " -c=[code_cine] Specify cine code\n";
18) echo " -t=[number] Specify phone number\n";
19) echo " -d=[sms.domain.tld] Specify SMS mail domaine\n";
20) exit();
21) }
22)
23) if (isset($options["c"]) && $options["c"]!==false) {
24) $code_cine=$options["c"];
25) }
26) else die("You must provide cine code with -c=XXX parameter.\n");
27)
|
Leave possibility to run sc...
Benjamin Renard authored 10 years ago
|
28) $send_to=false;
29) $mail_domain=false;
|
Initial commit
Benjamin Renard authored 10 years ago
|
30) if (isset($options["t"]) && $options["t"]!==false) {
31) $send_to=$options["t"];
|
Leave possibility to run sc...
Benjamin Renard authored 10 years ago
|
32) if (isset($options["d"]) && $options["d"]!==false) {
33) $mail_domain=$options["d"];
34) }
35) else die("You must provide SMS mail domain with -d=domain.tld parameter.\n");
|
Initial commit
Benjamin Renard authored 10 years ago
|
36) }
37)
38) try {
39) $helper = new AlloHelper;
40) $result = $helper->showtimesByTheaters($code_cine);
41) }
42) catch( ErrorException $error ) {
43) die("Error retreiving informations (Err. n°". $error->getCode(). ") : ". $error->getMessage());
44) }
45)
46) try {
47) $name_cine=null;
48) $movies=array();
49) foreach($result->theaterShowtimes as $t) {
50) $name_cine=$t->place->theater->name;
51) foreach($t->movieShowtimes as $mst) {
52) $movie=utf8_encode($mst->onShow->movie->title);
53) $suf=array();
54) if ($mst->screenFormat['$']=='3D') {
55) $suf[]='3D';
56) }
57) if ($mst->version->code!=6001) {
58) $suf[]='VO';
59) }
60) if(count($suf)>0) {
61) $movie.=' ('.implode('/',$suf).')';
62) }
63)
64) if (!isset($movies[$movie])) {
65) $movies[$movie]=array();
66) }
67)
68) foreach($mst->scr as $day) {
69) $date=DateTime::createFromFormat('Y-m-d',$day['d']);
70) $jour=str_replace('.','',strftime('%a',$date->getTimestamp()));
71) if(!isset($movies[$movie][$jour])) $movies[$movie][$jour]=array();
72) foreach($day['t'] as $t) {
73) $movies[$movie][$jour][]=$t['$'];
74) }
75) }
76) }
77) }
78) }
79) catch( ErrorException $error ) {
80) die("Error parsing informations (Err. n°".$error->getCode().") : ".$error->getMessage());
81) }
82)
83) // Format movies informations
84) $fmovies=group_days($movies);
85)
86) // Calculate start/end of cine week
87) $start_date=new Datetime(date('Y-m-d').' 00:00:00');
88) $start=$start_date->format('d/m');
89) $start_time=$start_date->getTimestamp();
90) $start_wd=(int)date('N',$start_time);
91) $end_time=$start_time+(24*3600*((9-$start_wd)%7));
92) $end=date('d/m',$end_time);
93)
94) // Format Message
95) $msg="Cinema $name_cine\nProgramme du $start au $end\n";
96)
97) foreach($fmovies as $m => $ps){
98) $msg.="$m : ";
99) $hss=array();
100) foreach($ps as $p => $hs) {
101) $hss[]="$p ".implode(' & ',$hs);
102) }
103) $msg.=implode(' / ',$hss)."\n";
104) }
105)
106) // Remove accents
107) $msg=$msg=withoutAccents($msg);
108)
|
Leave possibility to run sc...
Benjamin Renard authored 10 years ago
|
109) if ($send_to && $mail_domain) {
110) // Format mail
111) $mail="$send_to@$mail_domain";
|
Initial commit
Benjamin Renard authored 10 years ago
|
112)
|
Leave possibility to run sc...
Benjamin Renard authored 10 years ago
|
113) // Display message
114) echo "Send to $mail :\n\n$msg";
|
Initial commit
Benjamin Renard authored 10 years ago
|
115)
|