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