forked from jpatokal/openflights
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimezones.php
More file actions
57 lines (52 loc) · 1.79 KB
/
timezones.php
File metadata and controls
57 lines (52 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
include_once('../php/helper.php');
include_once('../php/simple_html_dom.php');
// Request timezone for airports and add it to DB
// <timezone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.earthtools.org/timezone.xsd">
// <version>1.1</version>
// <location>
// <latitude>40.71417</latitude>
// <longitude>-74.00639</longitude>
// </location>
// <offset>-5</offset>
// <suffix>R</suffix>
// <localtime>4 Dec 2005 12:06:56</localtime>
// <isotime>2005-12-04 12:06:56 -0500</isotime>
// <utctime>2005-12-04 17:06:56</utctime>
// <dst>False</dst>
// </timezone>
$db = mysql_connect("localhost", "openflights");
mysql_select_db("flightdb2",$db);
$sql = "select * from airports where timezone is null";
$result = mysql_query($sql, $db) or die ('Database error: ' . $sql . ', error ' . mysql_error());
while($row = mysql_fetch_assoc($result)) {
$name = format_airport($row);
$lon = $row["x"];
$lat = $row["y"];
$apid = $row["apid"];
$html = file_get_html("http://www.earthtools.org/timezone/$lat/$lon");
$tz = $html->find('offset', 0)->plaintext;
$dst = $html->find('dst', 0)->plaintext;
$count++;
print "$count: $name ($lon, $lat): Timezone $tz, DST $dst";
switch($dst) {
case "True":
$dstcode = "E"; // European
break;
case "False":
$dstcode = "N"; // None
break;
case "Unknown":
$dstcode = "U";
break;
}
$sql = "UPDATE airports SET timezone=$tz, dst='$dstcode' WHERE apid=$apid";
$update = mysql_query($sql, $db) or die ('Database error: ' . $sql . ', error ' . mysql_error());
if(mysql_affected_rows() != 1) {
die ('Database error: ' . $sql . ', error ' . mysql_error());
}
print " [OK]\n";
// Don't spam service (max 1 request/sec allowed)
sleep(5);
}
?>