Guest User

Untitled

a guest
Mar 5th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.85 KB | None | 0 0
  1. curl_getinfo output
  2.  
  3.    [url] => https://crest-tq.eveonline.com/market/10000002/orders/sell/?type=https://crest-tq.eveonline.com/inventory/types/10204/
  4.     [content_type] => application/vnd.ccp.eve.MarketOrderCollection-v1+json; charset=utf-8
  5.     [http_code] => 200
  6.     [header_size] => 614
  7.     [request_size] => 148
  8.     [filetime] => -1
  9.     [ssl_verify_result] => 20
  10.     [redirect_count] => 0
  11.     [total_time] => 2.075
  12.     [namelookup_time] => 0
  13.     [connect_time] => 0.296
  14.     [pretransfer_time] => 1.419
  15.     [size_upload] => 0
  16.     [size_download] => 10580
  17.     [speed_download] => 5098
  18.     [speed_upload] => 0
  19.     [download_content_length] => 10580
  20.     [upload_content_length] => 0
  21.     [starttransfer_time] => 1.778
  22.     [redirect_time] => 0
  23.     [redirect_url] =>
  24.     [primary_ip] => 87.237.34.201
  25.  
  26.  
  27. Actual php
  28.  
  29. <?php
  30. $startTime=time();
  31.  
  32. function get_data($url) {
  33.     $ch = curl_init();
  34.     $timeout = 5;
  35.     curl_setopt($ch, CURLOPT_URL, $url);
  36.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  37.     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  38.     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);  
  39.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);  
  40.     curl_setopt($ch, CURLOPT_POST, false);
  41.     $data = curl_exec($ch);
  42.  
  43. $info = curl_getinfo($ch);
  44. echo '<pre>' . print_r($info);
  45.    
  46.     curl_close($ch);
  47.     return $data;
  48.     }
  49.  
  50. $con = new mysqli('localhost', 'root', '', 'corpmarket');
  51.         if ($con->connect_errno) {
  52.             die('Failed to connect to MySQL: ' . $con->connect_error);
  53.             }
  54.  
  55. $region = 10000002;
  56. $stationid = 60003760;
  57.  
  58. $gettradelist_sql = "SELECT typeid FROM corpmarket.tradelist where traded = 1 limit 20";
  59. $list = $con->query($gettradelist_sql);
  60.     if (false === $list) {
  61.     die('Failed type list query the error was ' . $con->error);
  62.     }
  63.  
  64.    
  65. foreach ($list as $row) {
  66.         if (!array_key_exists('typeid', $row)) {
  67.         print 'No type id found for row <br><pre>';
  68.         print_r($row);
  69.         print '</pre>';
  70.         continue;
  71.         }
  72.    
  73.         $typeID = $row['typeid'];
  74.         $url = 'https://crest-tq.eveonline.com/market/' . $region . '/orders/sell/?type=https://crest-tq.eveonline.com/inventory/types/' . $typeID . '/';
  75.         $crest = get_data($url);
  76.         $json = json_decode($crest, true);
  77.  
  78.     $lowest = PHP_INT_MAX;
  79.     foreach ($json['items'] as $item) {
  80.           if ((int)$stationid === (int)$item['location']['id']) {
  81.             $lowest = min($lowest, (float)$item['price']);
  82.                }
  83.             }  
  84. if ($lowest == 2147483647)
  85.     { $lowest = 0;  }
  86.  
  87.         $sql = 'INSERT IGNORE INTO temp_crest_prices (typeID, regionid, stationid, price ) VALUES ';
  88.         $sql .= "('" . implode("','", [$typeID, $region, $stationid, $lowest]) . "')";
  89.  
  90.  echo $sql . "<br>";
  91.        
  92.  
  93.     }
  94.  
  95. $endTime = time();
  96. echo '<br><hr><br>';
  97. echo 'StartTime: ' . $startTime . '<br>';
  98. echo 'EndTime: ' . $endTime . '<br>';
  99. $totalTime = $endTime - $startTime;
  100. echo 'TotalTime: ' . $totalTime . '<br>';
  101.  
  102. ?>
Add Comment
Please, Sign In to add comment