Advertisement
Zappity

UpdatePrices2.php

Aug 6th, 2016
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.17 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Connects.php defines the database connection details and API keys
  5. */
  6. include 'Connects.php' ;
  7.  
  8. function update_price($typeID) {
  9.  
  10.   include 'Connects.php' ;
  11.  
  12.   $source = '' ;
  13.   $sellJita = 0 ;
  14.   $buyJita = 0 ;
  15.   // Check price age. If it hasn't been updated in the last two hours do it
  16.   $resultCount=$db->query("SELECT count(*) as total from prices WHERE typeID = $typeID AND updated > DATE_SUB(NOW(), INTERVAL 2 HOUR)");
  17.   $rowCount = $resultCount->fetch(PDO::FETCH_ASSOC) ;
  18.   if ( $rowCount['total'] == '0') {
  19.     $url = "http://api.eve-central.com/api/marketstat?usesystem=30000142&typeid=$typeID" ;
  20.     if ($pricexml = file_get_contents($url)) {
  21.       $xml5 = new SimpleXMLElement($pricexml) ;
  22.       $item = $xml5->xpath('/evec_api/marketstat/type[@id='.$typeID.']') ;
  23.        
  24. //    $sellJita = (float) $item[0]->sell->min ;
  25. //    $buyJita = (float) $item[0]->buy->max ;
  26.       $sellJita = (float) $item[0]->sell->percentile ;
  27.       $buyJita = (float) $item[0]->buy->percentile ;
  28.       $source = 'eve-central' ;
  29.  
  30.  
  31. /*
  32.       if ( $buyJita == 0 OR $buyJita == 0.00 ) { // eve-marketdata alternative
  33.         $url = "http://api.eve-marketdata.com/api/item_prices2.xml?char_name=Zappity&region_ids=10000002&buysell=b&type_ids=$typeID" ;
  34.         $pricexml = file_get_contents($url) ;
  35.         $xml7 = new SimpleXMLElement($pricexml) ;
  36.         foreach ($xml7 -> result -> rowset-> row as $row7) {
  37.           $buyJita = $row7['price'] ;
  38.         }
  39.         $url = "http://api.eve-marketdata.com/api/item_prices2.xml?char_name=Zappity&region_ids=10000002&buysell=s&type_ids=$typeID" ;
  40.         $pricexml = file_get_contents($url) ;
  41.         $xml8 = new SimpleXMLElement($pricexml) ;
  42.         foreach ($xml8 -> result -> rowset-> row as $row8) {
  43.           $sellJita = $row8['price'] ;
  44.         }
  45.         $source = 'eve-marketdata' ;
  46.       }
  47. */
  48.       if ( $buyJita == 0 ) {
  49.         $source = 'zeros' ;
  50.       }
  51.  
  52.       $db->query(" UPDATE prices SET
  53.        sellJita = $sellJita,
  54.        buyJita = $buyJita,
  55.        source = '$source',
  56.        updated = NOW()
  57.        WHERE typeID = '$typeID' ") or die("ContractValues.php error 4171475") ;
  58.     }
  59.   }
  60.  
  61. }
  62.  
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement