-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompetition.php
87 lines (73 loc) · 2.79 KB
/
competition.php
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*
*
*
* C:\xampp\php\php -f "C:\xampp\htdocs\Eve_industry_data\competition.php
*/
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "test";
//if ($_GET["sellVol"] != null) {
// $sellVol = (int) $_GET["sellVol"];}
// else {
$sellVol = 50000;
//}
//if ($_GET["buyVol"] != null) {
// $buyVol = (int) $_GET["sellVol"];}
// else {
$buyVol = 50000;
//}
//if ($_GET["delta"] != null) {
// $delta = (int) $_GET["sellVol"];}
// else {
$delta = 1.5;
//}
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully" . PHP_EOL;
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage() . PHP_EOL;
}
$query = $conn->prepare(
"SELECT i.typeID, i.typeName, j.typeID, j.sellVolume, j.buyVolume, j.max, j.min, j.profit, j.delta "
. "FROM invtypes AS i "
. "INNER JOIN jitamarket AS J ON j.typeID = i.typeID "
. "WHERE j.buyVolume > {$buyVol} AND j.sellVolume > {$sellVol} "
. "AND j.delta > {$delta} "
. "AND i.marketGroupID NOT IN (SELECT `marketGroupID` FROM `invmarketgroups` "
. "WHERE `parentGroupID` = '19' ORDER BY `marketGroupName`) " //market group 19 is trade goods so removing it
. "ORDER BY j.profit DESC Limit 0,30");
$query->execute();
$profitable_items = $query->fetchAll();
//echo "<pre>" . print_r($profitable_items) . "</pre>";
foreach ($profitable_items as $row) {
$item = $row['typeID'];
$curl_handle = curl_init('http://api.eve-central.com/api/quicklook?typeid=' . $item . '&usesystem=30000142');
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true); // Fetch the contents too
$http = curl_exec($curl_handle);
curl_close($curl_handle);
echo 'Webpage returned.' . PHP_EOL;
// processWebpage($http);
$xml = simplexml_load_string($http);
echo 'Data returned ' . $xml->quicklook->sell_orders->order->count() . PHP_EOL;
$numOfItems = $xml->quicklook->sell_orders->order->count();
global $conn;
try {
$sql = $conn->query("INSERT INTO jitamarket (typeID, orders) "
. "VALUES ('$item', '$numOfItems') "
. "ON DUPLICATE KEY "
. "UPDATE orders=VALUES(orders)");
$sql->execute();
echo "Data entered for " . $item . PHP_EOL;
} catch (PDOException $e) {
echo "Cannot add entry: " . $e->getMessage();
}
}
?>