1 | <?php |
---|
2 | if (gmdate('H:i') != '12:59') |
---|
3 | { |
---|
4 | exit; |
---|
5 | } |
---|
6 | |
---|
7 | include_once('evedb.php'); |
---|
8 | |
---|
9 | function startElement($parser, $name, $attrs) |
---|
10 | { |
---|
11 | global $sovtime, $edb; |
---|
12 | |
---|
13 | if ($name == 'ROW') |
---|
14 | { |
---|
15 | $rows = join(',', array_keys($attrs)); |
---|
16 | array_unshift($attrs, $sovtime); |
---|
17 | $values = join("','", $attrs); |
---|
18 | $query = 'INSERT INTO mapsovereignty (`date`,'.$rows.') VALUES (\''.$values.'\')'; |
---|
19 | $edb->query($query); |
---|
20 | } |
---|
21 | } |
---|
22 | |
---|
23 | function endElement($parser, $name) |
---|
24 | { |
---|
25 | |
---|
26 | } |
---|
27 | |
---|
28 | function characterData($parser, $data) |
---|
29 | { |
---|
30 | global $sovtime; |
---|
31 | if (!isset($sovtime)) |
---|
32 | { |
---|
33 | $sovtime = $data; |
---|
34 | global $edb; |
---|
35 | |
---|
36 | $query = "select count(*) as cnt from mapsovereignty where `date`='".$sovtime."'"; |
---|
37 | $edb->query($query); |
---|
38 | $result = $edb->fetch_array(); |
---|
39 | if ($result['cnt'] != 0) |
---|
40 | { |
---|
41 | exit; |
---|
42 | //die('found '.$result['cnt'].' rows, aborting'); |
---|
43 | } |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | if (empty($argv)) |
---|
48 | { |
---|
49 | $data = file_get_contents('http://api.eve-online.com/map/Sovereignty.xml.aspx'); |
---|
50 | } |
---|
51 | else |
---|
52 | { |
---|
53 | if (substr($argv[1], -2, 2) == 'gz') |
---|
54 | { |
---|
55 | $data = ''; |
---|
56 | $p = gzopen($argv[1], 'r'); |
---|
57 | while ($line = gzread($p, 4096)) |
---|
58 | { |
---|
59 | $data .= $line; |
---|
60 | } |
---|
61 | } |
---|
62 | else |
---|
63 | { |
---|
64 | $data = file_get_contents($argv[1]); |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | $p = xml_parser_create(); |
---|
69 | xml_set_element_handler($p, "startElement", "endElement"); |
---|
70 | xml_set_character_data_handler($p, "characterData"); |
---|
71 | |
---|
72 | xml_parse($p, $data, true); |
---|
73 | xml_parser_free($p); |
---|
74 | |
---|
75 | if (empty($argv)) |
---|
76 | { |
---|
77 | $fp = gzopen('data/Sovereignty.'.date('Y-m-d', strtotime($sovtime)).'.xml.gz', 'wb9'); |
---|
78 | gzwrite($fp, $data); |
---|
79 | gzclose($fp); |
---|
80 | } |
---|
81 | |
---|
82 | $date1 = date('Y-m-d H:i:s', strtotime($sovtime)-24*3600); |
---|
83 | /* |
---|
84 | $query = "SELECT count(*) as cnt |
---|
85 | FROM mapsovereignty m1 |
---|
86 | left join mapsovereignty m2 on m1.solarSystemID=m2.solarSystemID and m2.date='$date1' |
---|
87 | left join mapsolarsystems on m1.solarSystemID=mapsolarsystems.solarSystemID |
---|
88 | WHERE m1.date='$sovtime' |
---|
89 | and (m1.allianceID != m2.allianceID or m2.allianceID is null) |
---|
90 | and m1.factionID = 0"; |
---|
91 | $edb->query($query); |
---|
92 | $num = $edb->num_rows();*/ |
---|
93 | $num = 1; |
---|
94 | if ($num == 0) |
---|
95 | { |
---|
96 | $edb->query("delete from mapsovereignty where `date` = '".$sovtime."'"); |
---|
97 | $edb->query("delete from mapsovdates where `date`='".$sovtime."'"); |
---|
98 | } |
---|
99 | else |
---|
100 | { |
---|
101 | // update the sovdata table |
---|
102 | $edb->query("insert into mapsovdates (`date`) VALUES ('".$sovtime."')"); |
---|
103 | $edb->query("insert into maprendertarget (date1,date2,added,prio) VALUES ('$date1', '$sovtime', '$sovtime', 10)"); |
---|
104 | } |
---|
105 | include('readalli.php5'); |
---|
106 | ?> |
---|