· 6 years ago · Nov 24, 2019, 09:14 PM
1<?php
2
3$airline = "AAL"; //Three-Letter Code
4
5$ref = "1122"; //Reference code used for DB
6
7if($airline == null){return;}
8//GOLD CODE
9$con=mysqli_connect("localhost","77","77","77");
10// Check connection
11if (mysqli_connect_errno($con))
12{
13echo "Failed to connect to MySQL: " . mysqli_connect_error();
14}
15$table_name = $airline."_schedules_".$ref; //A table name that goes along with the reference ID Always Unique.
16$sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
17 `id` int(11) NOT NULL AUTO_INCREMENT,
18 `code` char(3) NOT NULL DEFAULT '',
19 `flightnum` varchar(10) NOT NULL,
20 `depicao` varchar(4) NOT NULL DEFAULT '',
21 `arricao` varchar(4) NOT NULL DEFAULT '',
22 `route` text NOT NULL,
23 `aircraft` text NOT NULL,
24 `flightlevel` varchar(6) NOT NULL DEFAULT '32000',
25 `distance` float NOT NULL DEFAULT '0',
26 `deptime` varchar(15) NOT NULL DEFAULT '',
27 `arrtime` varchar(15) NOT NULL DEFAULT '',
28 `flighttime` float NOT NULL DEFAULT '0',
29 `notes` text NOT NULL,
30 `price` float NOT NULL,
31 `flighttype` varchar(1) NOT NULL DEFAULT 'P',
32 `daysofweek` varchar(7) NOT NULL DEFAULT '1234560',
33 `enabled` int(11) NOT NULL DEFAULT '1',
34 PRIMARY KEY (`id`),
35 KEY `depicao` (`depicao`),
36 KEY `flightnum` (`flightnum`),
37 KEY `depicao_arricao` (`depicao`,`arricao`),
38 KEY `code` (`code`),
39 KEY `idx_code_flightnum` (`code`,`flightnum`)
40) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;";
41
42if(mysqli_query($con, $sql)){
43
44$options = array(
45'trace' => true,
46'exceptions' => 0,
47'login' => '7777',
48'password' => '7777',
49);
50$client = new SoapClient('http://flightxml.flightaware.com/soap/FlightXML2/wsdl', $options);
51
52$date_end = time();//curent time in unix
53$date_beg = time() - 60*60*24*7;//current time 7 days ago in unix
54
55$sizeparams = array(
56 "max_size" => 20 //ORG = 15000
57);
58$client->SetMaximumResultSize($sizeparams);
59// Will get you SCHEDULED flights in that airline for up to 24 hours ahead. Will automatically include codeshares. "35,000" is used to limit my spending at $0.01/15 results. You can increase the value to get more results. In some cases, this will be necessary to get ALL the scheduled flights.
60$params = array(
61 "startDate" => time(),
62 "endDate" => time()+(24 * 60 * 60),
63 "origin" => "",
64 "destination" => "",
65 "airline" => $airline,
66 "flightno"=> "",
67 "howMany" => 20, //ORG = 35,000
68 "offset" => 0
69);
70
71/*
72Up to this point we're doing good.
73*/
74
75$result = $client->AirlineFlightSchedules($params);
76$flights = $result->AirlineFlightSchedulesResult->data; //retrieve flight results
77$count = 0;
78$implemented = 0;
79foreach ($flights as $flight) {
80$count++;
81$ident_carrier = substr($flight->ident, 0, 3);
82$actualident_carrier = substr($flight->actual_ident, 0, 3);
83$notes = "";
84if($ident_carrier == $airline && ( $actualident_carrier != $airline || $actualident_carrier != "")){
85//Flight Flown booked by airline but operated by another carrier
86if($actualident_carrier == ""){
87//Do nothing
88}else{
89$notes .= "Flight Operated by ". substr($flight->actual_ident, 0, 3).". "; //Add that to the notes
90}
91$implemented++;
92}else if($ident_carrier != $airline){
93//Probably a duplicate, just check the next flight
94//continue;
95}
96
97$identity = $flight->ident;
98$flightid = $flight->ident; //Could be mixed with ident
99$orig = $flight->origin;
100$dest = $flight->destination;
101$deptim2 = $flight->departuretime;
102$deptim = gmdate("H:i", $deptim2);
103$arrtim2 = $flight->arrivaltime;
104$arrtim = gmdate("H:i", $arrtim2);
105$atype = $flight->aircrafttype;
106$notes .= $flight->meal_service;
107
108$code = substr($flight->ident, 0, 3);
109$flightnum = substr( $flightid, 3);
110//$flightnum = str_replace($airline, "", $identity);
111
112$result3 = mysqli_query($con,"SELECT * FROM airports WHERE icao='$orig'");
113$result3 = mysqli_fetch_assoc($result3);
114
115$result4 = mysqli_query($con,"SELECT * FROM airports WHERE icao='$dest'");
116$result4 = mysqli_fetch_assoc($result4);
117
118$lat1 = $result3['lat'];
119$lat2 = $result4['lat'];
120$lon1 = $result3['lng'];
121$lon2 = $result4['lng'];
122$theta = $lon1 - $lon2;
123$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
124$dist = acos($dist);
125$dist = rad2deg($dist);
126$dist = $dist * 69.11;
127
128$routing = "See flightaware for routing options";
129$cruise = 32000;
130$utime = ($arrtim2 - $deptim2) / 60 / 60;
131$utime = number_format((float)$utime, 2, '.', '');
132$price = 500;
133
134mysqli_query($con,"INSERT INTO `$table_name`(code, flightnum, depicao, arricao, aircraft, deptime, arrtime, flighttime, distance, notes, price) VALUES('$code', '$flightnum', '$orig', '$dest', '$atype', '$deptim', '$arrtim', '$utime', '$dist', '$notes', '$price')") or die(mysqli_error($con));
135}
136
137echo ' Finished. Retrieved ' . $count . ' Raw Schedules. ' . $implemented . ' Were implemented';
138mysqli_close($con);
139}
140?>
141
142<pre>
143<?php print_r($flights); ?>
144</pre>