Advertisement
Guest User

Untitled

a guest
May 10th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 KB | None | 0 0
  1. <?php
  2. function regionalorders()
  3. {
  4. //set variables
  5. $servername = "localhost";
  6. $username = "root";
  7. $password = "";
  8. // Create connection
  9. $conn = new mysqli($servername, $username, $password);
  10. // Check connection
  11. if ($conn->connect_error) {
  12.     die("Connection failed: " . $conn->connect_error);
  13. }
  14. echo "Connected successfully";
  15. //set variables
  16. $page = "1";
  17. $thistime = time();
  18. $source_id = "10000002";
  19. while (true) {
  20.   $ins = [];
  21. // make esi call to public order endpoint and get json data
  22. $content = file_get_contents('https://esi.tech.ccp.is/latest/markets/'.$source_id.'/orders/?datasource=tranquility&order_type=all&page='.$page);
  23. //decode JSON data to PHP array
  24. $orders = json_decode($content,true);
  25. $response_code = explode(' ', $http_response_header[0])[1];
  26. if ($response_code == 200) {
  27.   foreach ($orders as $0) {
  28.     $ins[] = "($source_id,{$o['duration']},0{$o['is_buy_order']},UNIX_TIMESTAMP(STR_TO_DATE('{$o['issued']}','%Y-%m-%dT%H:%i:%sZ')),{$o['location_id']},{$o['min_volume']},{$o['order_id']},{$o['price']},{$o['range']},{$o['type_id']},{$o['volume_remain']},{$o['volume_total']},$thistime)";
  29.   }
  30.   if (count($ins) > 0) {
  31.           $page++;
  32.           while (count($ins) > 0) {
  33.             $thisins = array_slice($ins, 0, 1000);
  34.             $ins = array_slice($ins, 1000);
  35.             $conn->query("INSERT INTO markets.orders VALUES " . implode(',', $thisins) . " ON DUPLICATE KEY UPDATE issued=VALUES(issued),price=VALUES(price),volume_remain=VALUES(volume_remain),last_seen=$thistime");
  36.           }
  37.         } else {
  38.           $conn->query("DELETE FROM markets.orders WHERE source=$source_id AND last_seen < ($thistime-60)");
  39.           return;
  40.         }
  41.       } else {
  42.         return;
  43.       }
  44.     }
  45.   }
  46.   ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement