mirror of
https://github.com/EDCD/EDDN.git
synced 2025-06-18 07:52:59 +03:00
Update examples
This commit is contained in:
parent
a733ff22ed
commit
eb137fbcba
@ -40,18 +40,18 @@ $oldTime = false;
|
|||||||
function echoLog($str)
|
function echoLog($str)
|
||||||
{
|
{
|
||||||
global $oldTime, $logVerboseFile;
|
global $oldTime, $logVerboseFile;
|
||||||
|
|
||||||
if($logVerboseFile !== false)
|
if($logVerboseFile !== false)
|
||||||
$logVerboseFileParsed = str_replace('%DATE%', date('Y-m-d'), $logVerboseFile);
|
$logVerboseFileParsed = str_replace('%DATE%', date('Y-m-d'), $logVerboseFile);
|
||||||
|
|
||||||
if($logVerboseFile !== false && !file_exists($logVerboseFileParsed))
|
if($logVerboseFile !== false && !file_exists($logVerboseFileParsed))
|
||||||
{
|
{
|
||||||
file_put_contents(
|
file_put_contents(
|
||||||
$logVerboseFileParsed,
|
$logVerboseFileParsed,
|
||||||
'<style type="text/css">html { white-space: pre; font-family: Courier New,Courier,Lucida Sans Typewriter,Lucida Typewriter,monospace; }</style>'
|
'<style type="text/css">html { white-space: pre; font-family: Courier New,Courier,Lucida Sans Typewriter,Lucida Typewriter,monospace; }</style>'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($oldTime != date('H:i:s') || $oldTime === false)
|
if($oldTime != date('H:i:s') || $oldTime === false)
|
||||||
{
|
{
|
||||||
$oldTime = date('H:i:s');
|
$oldTime = date('H:i:s');
|
||||||
@ -59,9 +59,9 @@ function echoLog($str)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
$str = ' ' . ' | ' . $str;
|
$str = ' ' . ' | ' . $str;
|
||||||
|
|
||||||
fwrite(STDOUT, $str . PHP_EOL);
|
fwrite(STDOUT, $str . PHP_EOL);
|
||||||
|
|
||||||
if($logVerboseFile !== false)
|
if($logVerboseFile !== false)
|
||||||
file_put_contents(
|
file_put_contents(
|
||||||
$logVerboseFileParsed,
|
$logVerboseFileParsed,
|
||||||
@ -73,11 +73,11 @@ function echoLog($str)
|
|||||||
function echoLogJSON($json)
|
function echoLogJSON($json)
|
||||||
{
|
{
|
||||||
global $logJSONFile;
|
global $logJSONFile;
|
||||||
|
|
||||||
if($logJSONFile !== false)
|
if($logJSONFile !== false)
|
||||||
{
|
{
|
||||||
$logJSONFileParsed = str_replace('%DATE%', date('Y-m-d'), $logJSONFile);
|
$logJSONFileParsed = str_replace('%DATE%', date('Y-m-d'), $logJSONFile);
|
||||||
|
|
||||||
file_put_contents(
|
file_put_contents(
|
||||||
$logJSONFileParsed,
|
$logJSONFileParsed,
|
||||||
$json . PHP_EOL,
|
$json . PHP_EOL,
|
||||||
@ -106,11 +106,11 @@ while (true)
|
|||||||
echoLog('Connect to ' . $relayEDDN);
|
echoLog('Connect to ' . $relayEDDN);
|
||||||
echoLog('');
|
echoLog('');
|
||||||
echoLog('');
|
echoLog('');
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
$message = $subscriber->recv();
|
$message = $subscriber->recv();
|
||||||
|
|
||||||
if ($message === false)
|
if ($message === false)
|
||||||
{
|
{
|
||||||
$subscriber->disconnect($relayEDDN);
|
$subscriber->disconnect($relayEDDN);
|
||||||
@ -119,90 +119,90 @@ while (true)
|
|||||||
echoLog('');
|
echoLog('');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$message = zlib_decode($message);
|
$message = zlib_decode($message);
|
||||||
$json = json_decode($message, true);
|
$json = json_decode($message, true);
|
||||||
$converted = false;
|
$converted = false;
|
||||||
|
|
||||||
// Handle commodity v1
|
// Handle commodity v1
|
||||||
if($json['$schemaRef'] == 'http://schemas.elite-markets.net/eddn/commodity/1' . (($debugEDDN === true) ? '/test' : ''))
|
if($json['$schemaRef'] == 'https://eddn.edcd.io/schemas/commodity/1' . (($debugEDDN === true) ? '/test' : ''))
|
||||||
{
|
{
|
||||||
echoLogJSON($message);
|
echoLogJSON($message);
|
||||||
echoLog('Receiving commodity-v1 message...');
|
echoLog('Receiving commodity-v1 message...');
|
||||||
echoLog(' - Converting to v2...');
|
echoLog(' - Converting to v2...');
|
||||||
|
|
||||||
$temp = array();
|
$temp = array();
|
||||||
$temp['$schemaRef'] = 'http://schemas.elite-markets.net/eddn/commodity/2' . (($debugEDDN === true) ? '/test' : '');
|
$temp['$schemaRef'] = 'https://eddn.edcd.io/schemas/commodity/3' . (($debugEDDN === true) ? '/test' : '');
|
||||||
$temp['header'] = $json['header'];
|
$temp['header'] = $json['header'];
|
||||||
|
|
||||||
$temp['message'] = array();
|
$temp['message'] = array();
|
||||||
$temp['message']['systemName'] = $json['message']['systemName'];
|
$temp['message']['systemName'] = $json['message']['systemName'];
|
||||||
$temp['message']['stationName'] = $json['message']['stationName'];
|
$temp['message']['stationName'] = $json['message']['stationName'];
|
||||||
$temp['message']['timestamp'] = $json['message']['timestamp'];
|
$temp['message']['timestamp'] = $json['message']['timestamp'];
|
||||||
|
|
||||||
$temp['message']['commodities'] = array();
|
$temp['message']['commodities'] = array();
|
||||||
|
|
||||||
$commodity = array();
|
$commodity = array();
|
||||||
|
|
||||||
if(array_key_exists('itemName', $json['message']))
|
if(array_key_exists('itemName', $json['message']))
|
||||||
$commodity['name'] = $json['message']['itemName'];
|
$commodity['name'] = $json['message']['itemName'];
|
||||||
|
|
||||||
if(array_key_exists('buyPrice', $json['message']))
|
if(array_key_exists('buyPrice', $json['message']))
|
||||||
$commodity['buyPrice'] = $json['message']['buyPrice'];
|
$commodity['buyPrice'] = $json['message']['buyPrice'];
|
||||||
if(array_key_exists('stationStock', $json['message']))
|
if(array_key_exists('stationStock', $json['message']))
|
||||||
$commodity['supply'] = $json['message']['stationStock'];
|
$commodity['supply'] = $json['message']['stationStock'];
|
||||||
if(array_key_exists('supplyLevel', $json['message']))
|
if(array_key_exists('supplyLevel', $json['message']))
|
||||||
$commodity['supplyLevel'] = $json['message']['supplyLevel'];
|
$commodity['supplyLevel'] = $json['message']['supplyLevel'];
|
||||||
|
|
||||||
if(array_key_exists('sellPrice', $json['message']))
|
if(array_key_exists('sellPrice', $json['message']))
|
||||||
$commodity['sellPrice'] = $json['message']['sellPrice'];
|
$commodity['sellPrice'] = $json['message']['sellPrice'];
|
||||||
if(array_key_exists('demand', $json['message']))
|
if(array_key_exists('demand', $json['message']))
|
||||||
$commodity['demand'] = $json['message']['demand'];
|
$commodity['demand'] = $json['message']['demand'];
|
||||||
if(array_key_exists('demandLevel', $json['message']))
|
if(array_key_exists('demandLevel', $json['message']))
|
||||||
$commodity['demandLevel'] = $json['message']['demandLevel'];
|
$commodity['demandLevel'] = $json['message']['demandLevel'];
|
||||||
|
|
||||||
$temp['message']['commodities'][] = $commodity;
|
$temp['message']['commodities'][] = $commodity;
|
||||||
$json = $temp;
|
$json = $temp;
|
||||||
unset($temp, $commodity);
|
unset($temp, $commodity);
|
||||||
|
|
||||||
$converted = true;
|
$converted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Handle commodity v2
|
// Handle commodity v3
|
||||||
if($json['$schemaRef'] == 'http://schemas.elite-markets.net/eddn/commodity/2' . (($debugEDDN === true) ? '/test' : ''))
|
if($json['$schemaRef'] == 'https://eddn.edcd.io/schemas/commodity/3' . (($debugEDDN === true) ? '/test' : ''))
|
||||||
{
|
{
|
||||||
if($converted === false)
|
if($converted === false)
|
||||||
{
|
{
|
||||||
echoLogJSON($message);
|
echoLogJSON($message);
|
||||||
echoLog('Receiving commodity-v2 message...');
|
echoLog('Receiving commodity-v3 message...');
|
||||||
}
|
}
|
||||||
|
|
||||||
$authorised = false;
|
$authorised = false;
|
||||||
$excluded = false;
|
$excluded = false;
|
||||||
|
|
||||||
if(in_array($json['header']['softwareName'], $authorisedSoftwares))
|
if(in_array($json['header']['softwareName'], $authorisedSoftwares))
|
||||||
$authorised = true;
|
$authorised = true;
|
||||||
if(in_array($json['header']['softwareName'], $excludedSoftwares))
|
if(in_array($json['header']['softwareName'], $excludedSoftwares))
|
||||||
$excluded = true;
|
$excluded = true;
|
||||||
|
|
||||||
echoLog(' - Software: ' . $json['header']['softwareName'] . ' / ' . $json['header']['softwareVersion']);
|
echoLog(' - Software: ' . $json['header']['softwareName'] . ' / ' . $json['header']['softwareVersion']);
|
||||||
echoLog(' - ' . (($authorised === true)
|
echoLog(' - ' . (($authorised === true)
|
||||||
? 'AUTHORISED'
|
? 'AUTHORISED'
|
||||||
: (( $excluded === true) ? 'EXCLUDED' : 'UNAUTHORISED')
|
: (( $excluded === true) ? 'EXCLUDED' : 'UNAUTHORISED')
|
||||||
));
|
));
|
||||||
|
|
||||||
if($authorised === true && $excluded === false)
|
if($authorised === true && $excluded === false)
|
||||||
{
|
{
|
||||||
// Do what you want with the data...
|
// Do what you want with the data...
|
||||||
// Have fun !
|
// Have fun !
|
||||||
|
|
||||||
// For example
|
// For example
|
||||||
echoLog(' - Timestamp: ' . $json['message']['timestamp']);
|
echoLog(' - Timestamp: ' . $json['message']['timestamp']);
|
||||||
echoLog(' - Uploader ID: ' . $json['header']['uploaderID']);
|
echoLog(' - Uploader ID: ' . $json['header']['uploaderID']);
|
||||||
echoLog(' - System Name: ' . $json['message']['systemName']);
|
echoLog(' - System Name: ' . $json['message']['systemName']);
|
||||||
echoLog(' - Station Name: ' . $json['message']['stationName']);
|
echoLog(' - Station Name: ' . $json['message']['stationName']);
|
||||||
|
|
||||||
foreach($json['message']['commodities'] AS $commodity)
|
foreach($json['message']['commodities'] AS $commodity)
|
||||||
{
|
{
|
||||||
echoLog(' - Name: ' . $commodity['name']);
|
echoLog(' - Name: ' . $commodity['name']);
|
||||||
@ -217,13 +217,13 @@ while (true)
|
|||||||
}
|
}
|
||||||
// End example
|
// End example
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($authorised, $excluded);
|
unset($authorised, $excluded);
|
||||||
|
|
||||||
echoLog('');
|
echoLog('');
|
||||||
echoLog('');
|
echoLog('');
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($converted);
|
unset($converted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* $eddn = new EDDN(array(
|
* $eddn = new EDDN(array(
|
||||||
* 'uploaderID' => 'abcdef0123456789',
|
* 'uploaderID' => 'abcdef0123456789',
|
||||||
* 'softwareName' => 'My Awesome Market Uploader',
|
* 'softwareName' => 'My Awesome Market Uploader',
|
||||||
* 'softwareVersion' => 'v3.14'
|
* 'softwareVersion' => 'v3.14'
|
||||||
* ));
|
* )); *
|
||||||
*
|
|
||||||
* $result = $eddn->publishCommodityV1(
|
|
||||||
* 'Eranin',
|
|
||||||
* 'Azeban Orbital',
|
|
||||||
* time(),
|
|
||||||
* array(
|
|
||||||
* "itemName" => "Gold",
|
|
||||||
* "buyPrice" => 1024,
|
|
||||||
* "supply" => 7,
|
|
||||||
* "stationStock" => "Low",
|
|
||||||
* "sellPrice" => 1138,
|
|
||||||
* "demand" => 42,
|
|
||||||
* "demandLevel" => "Med"
|
|
||||||
* )
|
|
||||||
* ); // return true;
|
|
||||||
*
|
|
||||||
*
|
*
|
||||||
* $result = $eddn->publishCommodityV2(
|
* $result = $eddn->publishCommodityV2(
|
||||||
* 'Eranin',
|
* 'Eranin',
|
||||||
@ -47,117 +31,97 @@
|
|||||||
* )
|
* )
|
||||||
* )
|
* )
|
||||||
* ); // return true;
|
* ); // return true;
|
||||||
*
|
*
|
||||||
**/
|
**/
|
||||||
|
|
||||||
class EDDN
|
class EDDN
|
||||||
{
|
{
|
||||||
private static $_debug = true;
|
private static $_debug = true;
|
||||||
|
|
||||||
private static $_gateways = array(
|
private static $_gateways = array(
|
||||||
'http://eddn-gateway.elite-markets.net:8080/upload/',
|
'https://eddn.edcd.io:8080/upload/',
|
||||||
'http://eddn-gateway.ed-td.space:8080/upload/'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
private static $_schemas = array(
|
private static $_schemas = array(
|
||||||
'commodity-v1' => array(
|
'commodity-v3' => array(
|
||||||
'production' => 'http://schemas.elite-markets.net/eddn/commodity/1',
|
'production' => 'https://eddn.edcd.io/schemas/commodity/3',
|
||||||
'test' => 'http://schemas.elite-markets.net/eddn/commodity/1/test'
|
'test' => 'https://eddn.edcd.io/schemas/commodity/3/test',
|
||||||
),
|
),
|
||||||
'commodity-v2' => array(
|
|
||||||
'production' => 'http://schemas.elite-markets.net/eddn/commodity/2',
|
|
||||||
'test' => 'http://schemas.elite-markets.net/eddn/commodity/2/test'
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
private $_uploaderID = null;
|
private $_uploaderID = null;
|
||||||
private $_softwareName = null;
|
private $_softwareName = null;
|
||||||
private $_softwareVersion = null;
|
private $_softwareVersion = null;
|
||||||
|
|
||||||
public function __Construct(array $options)
|
public function __Construct(array $options)
|
||||||
{
|
{
|
||||||
if(array_key_exists('uploaderID', $options))
|
if(array_key_exists('uploaderID', $options))
|
||||||
$this->setUploaderID($options['uploaderID']);
|
$this->setUploaderID($options['uploaderID']);
|
||||||
else
|
else
|
||||||
throw new Exception('Option "uploaderID" is required.');
|
throw new Exception('Option "uploaderID" is required.');
|
||||||
|
|
||||||
if(array_key_exists('softwareName', $options))
|
if(array_key_exists('softwareName', $options))
|
||||||
$this->setSoftwareName($options['softwareName']);
|
$this->setSoftwareName($options['softwareName']);
|
||||||
else
|
else
|
||||||
throw new Exception('Option "softwareName" is required.');
|
throw new Exception('Option "softwareName" is required.');
|
||||||
|
|
||||||
if(array_key_exists('softwareVersion', $options))
|
if(array_key_exists('softwareVersion', $options))
|
||||||
$this->setSoftwareVersion($options['softwareVersion']);
|
$this->setSoftwareVersion($options['softwareVersion']);
|
||||||
else
|
else
|
||||||
throw new Exception('Option "softwareVersion" is required.');
|
throw new Exception('Option "softwareVersion" is required.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function publishCommodityV1($systemName, $stationName, $timestamp, array $commodity)
|
public function publishCommodityV3($systemName, $stationName, $timestamp, array $commodities)
|
||||||
{
|
|
||||||
$schema = self::$_schemas['commodity-v1'][((self::$_debug === true) ? 'test' : 'production')];
|
|
||||||
|
|
||||||
$message = array();
|
|
||||||
$message['systemName'] = $systemName;
|
|
||||||
$message['stationName'] = $stationName;
|
|
||||||
$message['timestamp'] = date('c', $timestamp);
|
|
||||||
|
|
||||||
foreach($commodity AS $key => $value)
|
|
||||||
$message[$key] = $value;
|
|
||||||
|
|
||||||
return $this->_postToEDDN($schema, $message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function publishCommodityV2($systemName, $stationName, $timestamp, array $commodities)
|
|
||||||
{
|
{
|
||||||
$schema = self::$_schemas['commodity-v2'][((self::$_debug === true) ? 'test' : 'production')];
|
$schema = self::$_schemas['commodity-v2'][((self::$_debug === true) ? 'test' : 'production')];
|
||||||
|
|
||||||
$message = array();
|
$message = array();
|
||||||
$message['systemName'] = $systemName;
|
$message['systemName'] = $systemName;
|
||||||
$message['stationName'] = $stationName;
|
$message['stationName'] = $stationName;
|
||||||
$message['timestamp'] = date('c', $timestamp);
|
$message['timestamp'] = date('c', $timestamp);
|
||||||
|
|
||||||
$message['commodities'] = $commodities;
|
$message['commodities'] = $commodities;
|
||||||
|
|
||||||
return $this->_postToEDDN($schema, $message);
|
return $this->_postToEDDN($schema, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function _generateHeader()
|
private function _generateHeader()
|
||||||
{
|
{
|
||||||
$header = array();
|
$header = array();
|
||||||
|
|
||||||
$header['uploaderID'] = $this->getUploaderID();
|
$header['uploaderID'] = $this->getUploaderID();
|
||||||
$header['softwareName'] = $this->getSoftwareName();
|
$header['softwareName'] = $this->getSoftwareName();
|
||||||
$header['softwareVersion'] = $this->getSoftwareVersion();
|
$header['softwareVersion'] = $this->getSoftwareVersion();
|
||||||
|
|
||||||
return $header;
|
return $header;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _postToEDDN($schema, array $message)
|
private function _postToEDDN($schema, array $message)
|
||||||
{
|
{
|
||||||
$array = array();
|
$array = array();
|
||||||
$array['$schemaRef'] = $schema;
|
$array['$schemaRef'] = $schema;
|
||||||
$array['header'] = $this->_generateHeader();
|
$array['header'] = $this->_generateHeader();
|
||||||
$array['message'] = $message;
|
$array['message'] = $message;
|
||||||
|
|
||||||
$json = json_encode($array);
|
$json = json_encode($array);
|
||||||
|
|
||||||
if(function_exists('curl_version'))
|
if(function_exists('curl_version'))
|
||||||
{
|
{
|
||||||
$gateway = self::$_gateways[array_rand(self::$_gateways)];
|
$gateway = self::$_gateways[array_rand(self::$_gateways)];
|
||||||
|
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $gateway);
|
curl_setopt($ch, CURLOPT_URL, $gateway);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt($ch, CURLOPT_POST, true);
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
|
||||||
|
|
||||||
$result = curl_exec($ch);
|
$result = curl_exec($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
unset($ch);
|
unset($ch);
|
||||||
|
|
||||||
if($result == 'OK')
|
if($result == 'OK')
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
@ -166,46 +130,46 @@ class EDDN
|
|||||||
else
|
else
|
||||||
throw new Exception('You must have CURL extension in order to publish to EDDN');
|
throw new Exception('You must have CURL extension in order to publish to EDDN');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function setUploaderID($value)
|
public function setUploaderID($value)
|
||||||
{
|
{
|
||||||
$this->_uploaderID = $value;
|
$this->_uploaderID = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUploaderID()
|
public function getUploaderID()
|
||||||
{
|
{
|
||||||
return $this->_uploaderID;
|
return $this->_uploaderID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function setSoftwareName($value)
|
public function setSoftwareName($value)
|
||||||
{
|
{
|
||||||
$this->_softwareName = $value;
|
$this->_softwareName = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSoftwareName()
|
public function getSoftwareName()
|
||||||
{
|
{
|
||||||
return $this->_softwareName;
|
return $this->_softwareName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function setSoftwareVersion($value)
|
public function setSoftwareVersion($value)
|
||||||
{
|
{
|
||||||
$this->_softwareVersion = $value;
|
$this->_softwareVersion = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSoftwareVersion()
|
public function getSoftwareVersion()
|
||||||
{
|
{
|
||||||
return $this->_softwareVersion;
|
return $this->_softwareVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function setDebug($value)
|
public function setDebug($value)
|
||||||
{
|
{
|
||||||
self::$_debug = $value;
|
self::$_debug = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDebug()
|
public function getDebug()
|
||||||
{
|
{
|
||||||
return self::$_debug;
|
return self::$_debug;
|
||||||
|
@ -50,10 +50,10 @@ def date(__format):
|
|||||||
__oldTime = False
|
__oldTime = False
|
||||||
def echoLog(__str):
|
def echoLog(__str):
|
||||||
global __oldTime, __logVerboseFile
|
global __oldTime, __logVerboseFile
|
||||||
|
|
||||||
if __logVerboseFile != False:
|
if __logVerboseFile != False:
|
||||||
__logVerboseFileParsed = __logVerboseFile.replace('%DATE%', str(date('%Y-%m-%d')))
|
__logVerboseFileParsed = __logVerboseFile.replace('%DATE%', str(date('%Y-%m-%d')))
|
||||||
|
|
||||||
if __logVerboseFile != False and not os.path.exists(__logVerboseFileParsed):
|
if __logVerboseFile != False and not os.path.exists(__logVerboseFileParsed):
|
||||||
f = open(__logVerboseFileParsed, 'w')
|
f = open(__logVerboseFileParsed, 'w')
|
||||||
f.write('<style type="text/css">html { white-space: pre; font-family: Courier New,Courier,Lucida Sans Typewriter,Lucida Typewriter,monospace; }</style>')
|
f.write('<style type="text/css">html { white-space: pre; font-family: Courier New,Courier,Lucida Sans Typewriter,Lucida Typewriter,monospace; }</style>')
|
||||||
@ -64,7 +64,7 @@ def echoLog(__str):
|
|||||||
__str = str(__oldTime) + ' | ' + str(__str)
|
__str = str(__oldTime) + ' | ' + str(__str)
|
||||||
else:
|
else:
|
||||||
__str = ' ' + ' | ' + str(__str)
|
__str = ' ' + ' | ' + str(__str)
|
||||||
|
|
||||||
print __str
|
print __str
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
@ -72,26 +72,26 @@ def echoLog(__str):
|
|||||||
f = open(__logVerboseFileParsed, 'a')
|
f = open(__logVerboseFileParsed, 'a')
|
||||||
f.write(__str + '\n')
|
f.write(__str + '\n')
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
def echoLogJSON(__json):
|
def echoLogJSON(__json):
|
||||||
global __logJSONFile
|
global __logJSONFile
|
||||||
|
|
||||||
if __logJSONFile != False:
|
if __logJSONFile != False:
|
||||||
__logJSONFileParsed = __logJSONFile.replace('%DATE%', str(date('%Y-%m-%d')))
|
__logJSONFileParsed = __logJSONFile.replace('%DATE%', str(date('%Y-%m-%d')))
|
||||||
|
|
||||||
f = open(__logJSONFileParsed, 'a')
|
f = open(__logJSONFileParsed, 'a')
|
||||||
f.write(str(__json) + '\n')
|
f.write(str(__json) + '\n')
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
echoLog('Starting EDDN Subscriber')
|
echoLog('Starting EDDN Subscriber')
|
||||||
echoLog('')
|
echoLog('')
|
||||||
|
|
||||||
context = zmq.Context()
|
context = zmq.Context()
|
||||||
subscriber = context.socket(zmq.SUB)
|
subscriber = context.socket(zmq.SUB)
|
||||||
|
|
||||||
subscriber.setsockopt(zmq.SUBSCRIBE, "")
|
subscriber.setsockopt(zmq.SUBSCRIBE, "")
|
||||||
subscriber.setsockopt(zmq.RCVTIMEO, __timeoutEDDN)
|
subscriber.setsockopt(zmq.RCVTIMEO, __timeoutEDDN)
|
||||||
|
|
||||||
@ -101,10 +101,10 @@ def main():
|
|||||||
echoLog('Connect to ' + __relayEDDN)
|
echoLog('Connect to ' + __relayEDDN)
|
||||||
echoLog('')
|
echoLog('')
|
||||||
echoLog('')
|
echoLog('')
|
||||||
|
|
||||||
poller = zmq.Poller()
|
poller = zmq.Poller()
|
||||||
poller.register(subscriber, zmq.POLLIN)
|
poller.register(subscriber, zmq.POLLIN)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
socks = dict(poller.poll(__timeoutEDDN))
|
socks = dict(poller.poll(__timeoutEDDN))
|
||||||
if socks:
|
if socks:
|
||||||
@ -113,83 +113,83 @@ def main():
|
|||||||
__message = zlib.decompress(__message)
|
__message = zlib.decompress(__message)
|
||||||
__json = simplejson.loads(__message)
|
__json = simplejson.loads(__message)
|
||||||
__converted = False
|
__converted = False
|
||||||
|
|
||||||
|
|
||||||
# Handle commodity v1
|
# Handle commodity v1
|
||||||
if __json['$schemaRef'] == 'http://schemas.elite-markets.net/eddn/commodity/1' + ('/test' if (__debugEDDN == True) else ''):
|
if __json['$schemaRef'] == 'https://eddn.edcd.io/schemas/commodity/1' + ('/test' if (__debugEDDN == True) else ''):
|
||||||
echoLogJSON(__message)
|
echoLogJSON(__message)
|
||||||
echoLog('Receiving commodity-v1 message...')
|
echoLog('Receiving commodity-v1 message...')
|
||||||
echoLog(' - Converting to v2...')
|
echoLog(' - Converting to v3...')
|
||||||
|
|
||||||
__temp = {}
|
__temp = {}
|
||||||
__temp['$schemaRef'] = 'http://schemas.elite-markets.net/eddn/commodity/2' + ('/test' if (__debugEDDN == True) else '')
|
__temp['$schemaRef'] = 'https://eddn.edcd.io/schemas/commodity/3' + ('/test' if (__debugEDDN == True) else '')
|
||||||
__temp['header'] = __json['header']
|
__temp['header'] = __json['header']
|
||||||
|
|
||||||
__temp['message'] = {}
|
__temp['message'] = {}
|
||||||
__temp['message']['systemName'] = __json['message']['systemName']
|
__temp['message']['systemName'] = __json['message']['systemName']
|
||||||
__temp['message']['stationName'] = __json['message']['stationName']
|
__temp['message']['stationName'] = __json['message']['stationName']
|
||||||
__temp['message']['timestamp'] = __json['message']['timestamp']
|
__temp['message']['timestamp'] = __json['message']['timestamp']
|
||||||
|
|
||||||
__temp['message']['commodities'] = []
|
__temp['message']['commodities'] = []
|
||||||
|
|
||||||
__commodity = {}
|
__commodity = {}
|
||||||
|
|
||||||
if 'itemName' in __json['message']:
|
if 'itemName' in __json['message']:
|
||||||
__commodity['name'] = __json['message']['itemName']
|
__commodity['name'] = __json['message']['itemName']
|
||||||
|
|
||||||
if 'buyPrice' in __json['message']:
|
if 'buyPrice' in __json['message']:
|
||||||
__commodity['buyPrice'] = __json['message']['buyPrice']
|
__commodity['buyPrice'] = __json['message']['buyPrice']
|
||||||
if 'stationStock' in __json['message']:
|
if 'stationStock' in __json['message']:
|
||||||
__commodity['supply'] = __json['message']['stationStock']
|
__commodity['supply'] = __json['message']['stationStock']
|
||||||
if 'supplyLevel' in __json['message']:
|
if 'supplyLevel' in __json['message']:
|
||||||
__commodity['supplyLevel'] = __json['message']['supplyLevel']
|
__commodity['supplyLevel'] = __json['message']['supplyLevel']
|
||||||
|
|
||||||
if 'sellPrice' in __json['message']:
|
if 'sellPrice' in __json['message']:
|
||||||
__commodity['sellPrice'] = __json['message']['sellPrice']
|
__commodity['sellPrice'] = __json['message']['sellPrice']
|
||||||
if 'demand' in __json['message']:
|
if 'demand' in __json['message']:
|
||||||
__commodity['demand'] = __json['message']['demand']
|
__commodity['demand'] = __json['message']['demand']
|
||||||
if'demandLevel' in __json['message']:
|
if'demandLevel' in __json['message']:
|
||||||
__commodity['demandLevel'] = __json['message']['demandLevel']
|
__commodity['demandLevel'] = __json['message']['demandLevel']
|
||||||
|
|
||||||
__temp['message']['commodities'].append(__commodity)
|
__temp['message']['commodities'].append(__commodity)
|
||||||
__json = __temp
|
__json = __temp
|
||||||
del __temp, __commodity
|
del __temp, __commodity
|
||||||
|
|
||||||
__converted = True
|
__converted = True
|
||||||
|
|
||||||
# Handle commodity v2
|
# Handle commodity v3
|
||||||
if __json['$schemaRef'] == 'http://schemas.elite-markets.net/eddn/commodity/2' + ('/test' if (__debugEDDN == True) else ''):
|
if __json['$schemaRef'] == 'https://eddn.edcd.io/schemas/commodity/3' + ('/test' if (__debugEDDN == True) else ''):
|
||||||
if __converted == False:
|
if __converted == False:
|
||||||
echoLogJSON(__message)
|
echoLogJSON(__message)
|
||||||
echoLog('Receiving commodity-v2 message...')
|
echoLog('Receiving commodity-v3 message...')
|
||||||
|
|
||||||
__authorised = False
|
__authorised = False
|
||||||
__excluded = False
|
__excluded = False
|
||||||
|
|
||||||
if __json['header']['softwareName'] in __authorisedSoftwares:
|
if __json['header']['softwareName'] in __authorisedSoftwares:
|
||||||
__authorised = True
|
__authorised = True
|
||||||
if __json['header']['softwareName'] in __excludedSoftwares:
|
if __json['header']['softwareName'] in __excludedSoftwares:
|
||||||
__excluded = True
|
__excluded = True
|
||||||
|
|
||||||
echoLog(' - Software: ' + __json['header']['softwareName'] + ' / ' + __json['header']['softwareVersion'])
|
echoLog(' - Software: ' + __json['header']['softwareName'] + ' / ' + __json['header']['softwareVersion'])
|
||||||
echoLog(' - ' + 'AUTHORISED' if (__authorised == True) else
|
echoLog(' - ' + 'AUTHORISED' if (__authorised == True) else
|
||||||
('EXCLUDED' if (__excluded == True) else 'UNAUTHORISED')
|
('EXCLUDED' if (__excluded == True) else 'UNAUTHORISED')
|
||||||
)
|
)
|
||||||
|
|
||||||
if __authorised == True and __excluded == False:
|
if __authorised == True and __excluded == False:
|
||||||
# Do what you want with the data...
|
# Do what you want with the data...
|
||||||
# Have fun !
|
# Have fun !
|
||||||
|
|
||||||
# For example
|
# For example
|
||||||
echoLog(' - Timestamp: ' + __json['message']['timestamp'])
|
echoLog(' - Timestamp: ' + __json['message']['timestamp'])
|
||||||
echoLog(' - Uploader ID: ' + __json['header']['uploaderID'])
|
echoLog(' - Uploader ID: ' + __json['header']['uploaderID'])
|
||||||
echoLog(' - System Name: ' + __json['message']['systemName'])
|
echoLog(' - System Name: ' + __json['message']['systemName'])
|
||||||
echoLog(' - Station Name: ' + __json['message']['stationName'])
|
echoLog(' - Station Name: ' + __json['message']['stationName'])
|
||||||
|
|
||||||
for __commodity in __json['message']['commodities']:
|
for __commodity in __json['message']['commodities']:
|
||||||
echoLog(' - Name: ' + __commodity['name'])
|
echoLog(' - Name: ' + __commodity['name'])
|
||||||
echoLog(' - Buy Price: ' + str(__commodity['buyPrice']))
|
echoLog(' - Buy Price: ' + str(__commodity['buyPrice']))
|
||||||
echoLog(' - Supply: ' + str(__commodity['supply'])
|
echoLog(' - Supply: ' + str(__commodity['supply'])
|
||||||
+ ((' (' + __commodity['supplyLevel'] + ')') if 'supplyLevel' in __commodity else '')
|
+ ((' (' + __commodity['supplyLevel'] + ')') if 'supplyLevel' in __commodity else '')
|
||||||
)
|
)
|
||||||
echoLog(' - Sell Price: ' + str(__commodity['sellPrice']))
|
echoLog(' - Sell Price: ' + str(__commodity['sellPrice']))
|
||||||
@ -197,33 +197,33 @@ def main():
|
|||||||
+ ((' (' + __commodity['demandLevel'] + ')') if 'demandLevel' in __commodity else '')
|
+ ((' (' + __commodity['demandLevel'] + ')') if 'demandLevel' in __commodity else '')
|
||||||
)
|
)
|
||||||
# End example
|
# End example
|
||||||
|
|
||||||
del __authorised, __excluded
|
del __authorised, __excluded
|
||||||
|
|
||||||
echoLog('')
|
echoLog('')
|
||||||
echoLog('')
|
echoLog('')
|
||||||
|
|
||||||
del __converted
|
del __converted
|
||||||
else:
|
else:
|
||||||
print 'Disconnect from ' + __relayEDDN + ' (After timeout)'
|
print 'Disconnect from ' + __relayEDDN + ' (After timeout)'
|
||||||
echoLog('')
|
echoLog('')
|
||||||
echoLog('')
|
echoLog('')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
subscriber.disconnect(__relayEDDN)
|
subscriber.disconnect(__relayEDDN)
|
||||||
break
|
break
|
||||||
|
|
||||||
except zmq.ZMQError, e:
|
except zmq.ZMQError, e:
|
||||||
subscriber.disconnect(__relayEDDN)
|
subscriber.disconnect(__relayEDDN)
|
||||||
|
|
||||||
echoLog('')
|
echoLog('')
|
||||||
echoLog('Disconnect from ' + __relayEDDN + ' (After receiving ZMQError)')
|
echoLog('Disconnect from ' + __relayEDDN + ' (After receiving ZMQError)')
|
||||||
echoLog('ZMQSocketException: ' + str(e))
|
echoLog('ZMQSocketException: ' + str(e))
|
||||||
echoLog('')
|
echoLog('')
|
||||||
|
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
@ -51,10 +51,10 @@ def date(__format):
|
|||||||
__oldTime = False
|
__oldTime = False
|
||||||
def echoLog(__str):
|
def echoLog(__str):
|
||||||
global __oldTime, __logVerboseFile
|
global __oldTime, __logVerboseFile
|
||||||
|
|
||||||
if __logVerboseFile != False:
|
if __logVerboseFile != False:
|
||||||
__logVerboseFileParsed = __logVerboseFile.replace('%DATE%', str(date('%Y-%m-%d')))
|
__logVerboseFileParsed = __logVerboseFile.replace('%DATE%', str(date('%Y-%m-%d')))
|
||||||
|
|
||||||
if __logVerboseFile != False and not os.path.exists(__logVerboseFileParsed):
|
if __logVerboseFile != False and not os.path.exists(__logVerboseFileParsed):
|
||||||
f = open(__logVerboseFileParsed, 'w')
|
f = open(__logVerboseFileParsed, 'w')
|
||||||
f.write('<style type="text/css">html { white-space: pre; font-family: Courier New,Courier,Lucida Sans Typewriter,Lucida Typewriter,monospace; }</style>')
|
f.write('<style type="text/css">html { white-space: pre; font-family: Courier New,Courier,Lucida Sans Typewriter,Lucida Typewriter,monospace; }</style>')
|
||||||
@ -65,7 +65,7 @@ def echoLog(__str):
|
|||||||
__str = str(__oldTime) + ' | ' + str(__str)
|
__str = str(__oldTime) + ' | ' + str(__str)
|
||||||
else:
|
else:
|
||||||
__str = ' ' + ' | ' + str(__str)
|
__str = ' ' + ' | ' + str(__str)
|
||||||
|
|
||||||
print (__str)
|
print (__str)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
@ -73,26 +73,26 @@ def echoLog(__str):
|
|||||||
f = open(__logVerboseFileParsed, 'a')
|
f = open(__logVerboseFileParsed, 'a')
|
||||||
f.write(__str + '\n')
|
f.write(__str + '\n')
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
def echoLogJSON(__json):
|
def echoLogJSON(__json):
|
||||||
global __logJSONFile
|
global __logJSONFile
|
||||||
|
|
||||||
if __logJSONFile != False:
|
if __logJSONFile != False:
|
||||||
__logJSONFileParsed = __logJSONFile.replace('%DATE%', str(date('%Y-%m-%d')))
|
__logJSONFileParsed = __logJSONFile.replace('%DATE%', str(date('%Y-%m-%d')))
|
||||||
|
|
||||||
f = open(__logJSONFileParsed, 'a')
|
f = open(__logJSONFileParsed, 'a')
|
||||||
f.write(str(__json) + '\n')
|
f.write(str(__json) + '\n')
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
echoLog('Starting EDDN Subscriber')
|
echoLog('Starting EDDN Subscriber')
|
||||||
echoLog('')
|
echoLog('')
|
||||||
|
|
||||||
context = zmq.Context()
|
context = zmq.Context()
|
||||||
subscriber = context.socket(zmq.SUB)
|
subscriber = context.socket(zmq.SUB)
|
||||||
|
|
||||||
subscriber.setsockopt(zmq.SUBSCRIBE, b"")
|
subscriber.setsockopt(zmq.SUBSCRIBE, b"")
|
||||||
subscriber.setsockopt(zmq.RCVTIMEO, __timeoutEDDN)
|
subscriber.setsockopt(zmq.RCVTIMEO, __timeoutEDDN)
|
||||||
|
|
||||||
@ -102,17 +102,17 @@ def main():
|
|||||||
echoLog('Connect to ' + __relayEDDN)
|
echoLog('Connect to ' + __relayEDDN)
|
||||||
echoLog('')
|
echoLog('')
|
||||||
echoLog('')
|
echoLog('')
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
__message = subscriber.recv()
|
__message = subscriber.recv()
|
||||||
|
|
||||||
if __message == False:
|
if __message == False:
|
||||||
subscriber.disconnect(__relayEDDN)
|
subscriber.disconnect(__relayEDDN)
|
||||||
echoLog('Disconnect from ' + __relayEDDN)
|
echoLog('Disconnect from ' + __relayEDDN)
|
||||||
echoLog('')
|
echoLog('')
|
||||||
echoLog('')
|
echoLog('')
|
||||||
break
|
break
|
||||||
|
|
||||||
echoLog('Got a message')
|
echoLog('Got a message')
|
||||||
|
|
||||||
__message = zlib.decompress(__message)
|
__message = zlib.decompress(__message)
|
||||||
@ -124,83 +124,83 @@ def main():
|
|||||||
echoLog('Failed to parse message as json')
|
echoLog('Failed to parse message as json')
|
||||||
|
|
||||||
__converted = False
|
__converted = False
|
||||||
|
|
||||||
|
|
||||||
# Handle commodity v1
|
# Handle commodity v1
|
||||||
if __json['$schemaRef'] == 'http://schemas.elite-markets.net/eddn/commodity/1' + ('/test' if (__debugEDDN == True) else ''):
|
if __json['$schemaRef'] == 'https://eddn.edcd.io/schemas/commodity/1' + ('/test' if (__debugEDDN == True) else ''):
|
||||||
echoLogJSON(__message)
|
echoLogJSON(__message)
|
||||||
echoLog('Receiving commodity-v1 message...')
|
echoLog('Receiving commodity-v1 message...')
|
||||||
echoLog(' - Converting to v2...')
|
echoLog(' - Converting to v3...')
|
||||||
|
|
||||||
__temp = {}
|
__temp = {}
|
||||||
__temp['$schemaRef'] = 'http://schemas.elite-markets.net/eddn/commodity/2' + ('/test' if (__debugEDDN == True) else '')
|
__temp['$schemaRef'] = 'https://eddn.edcd.io/schemas/commodity/3' + ('/test' if (__debugEDDN == True) else '')
|
||||||
__temp['header'] = __json['header']
|
__temp['header'] = __json['header']
|
||||||
|
|
||||||
__temp['message'] = {}
|
__temp['message'] = {}
|
||||||
__temp['message']['systemName'] = __json['message']['systemName']
|
__temp['message']['systemName'] = __json['message']['systemName']
|
||||||
__temp['message']['stationName'] = __json['message']['stationName']
|
__temp['message']['stationName'] = __json['message']['stationName']
|
||||||
__temp['message']['timestamp'] = __json['message']['timestamp']
|
__temp['message']['timestamp'] = __json['message']['timestamp']
|
||||||
|
|
||||||
__temp['message']['commodities'] = []
|
__temp['message']['commodities'] = []
|
||||||
|
|
||||||
__commodity = {}
|
__commodity = {}
|
||||||
|
|
||||||
if 'itemName' in __json['message']:
|
if 'itemName' in __json['message']:
|
||||||
__commodity['name'] = __json['message']['itemName']
|
__commodity['name'] = __json['message']['itemName']
|
||||||
|
|
||||||
if 'buyPrice' in __json['message']:
|
if 'buyPrice' in __json['message']:
|
||||||
__commodity['buyPrice'] = __json['message']['buyPrice']
|
__commodity['buyPrice'] = __json['message']['buyPrice']
|
||||||
if 'stationStock' in __json['message']:
|
if 'stationStock' in __json['message']:
|
||||||
__commodity['supply'] = __json['message']['stationStock']
|
__commodity['supply'] = __json['message']['stationStock']
|
||||||
if 'supplyLevel' in __json['message']:
|
if 'supplyLevel' in __json['message']:
|
||||||
__commodity['supplyLevel'] = __json['message']['supplyLevel']
|
__commodity['supplyLevel'] = __json['message']['supplyLevel']
|
||||||
|
|
||||||
if 'sellPrice' in __json['message']:
|
if 'sellPrice' in __json['message']:
|
||||||
__commodity['sellPrice'] = __json['message']['sellPrice']
|
__commodity['sellPrice'] = __json['message']['sellPrice']
|
||||||
if 'demand' in __json['message']:
|
if 'demand' in __json['message']:
|
||||||
__commodity['demand'] = __json['message']['demand']
|
__commodity['demand'] = __json['message']['demand']
|
||||||
if'demandLevel' in __json['message']:
|
if'demandLevel' in __json['message']:
|
||||||
__commodity['demandLevel'] = __json['message']['demandLevel']
|
__commodity['demandLevel'] = __json['message']['demandLevel']
|
||||||
|
|
||||||
__temp['message']['commodities'].append(__commodity)
|
__temp['message']['commodities'].append(__commodity)
|
||||||
__json = __temp
|
__json = __temp
|
||||||
del __temp, __commodity
|
del __temp, __commodity
|
||||||
|
|
||||||
__converted = True
|
__converted = True
|
||||||
|
|
||||||
# Handle commodity v2
|
# Handle commodity v3
|
||||||
if __json['$schemaRef'] == 'http://schemas.elite-markets.net/eddn/commodity/2' + ('/test' if (__debugEDDN == True) else ''):
|
if __json['$schemaRef'] == 'https://eddn.edcd.io/schemas/commodity/3' + ('/test' if (__debugEDDN == True) else ''):
|
||||||
if __converted == False:
|
if __converted == False:
|
||||||
echoLogJSON(__message)
|
echoLogJSON(__message)
|
||||||
echoLog('Receiving commodity-v2 message...')
|
echoLog('Receiving commodity-v3 message...')
|
||||||
|
|
||||||
__authorised = False
|
__authorised = False
|
||||||
__excluded = False
|
__excluded = False
|
||||||
|
|
||||||
if __json['header']['softwareName'] in __authorisedSoftwares:
|
if __json['header']['softwareName'] in __authorisedSoftwares:
|
||||||
__authorised = True
|
__authorised = True
|
||||||
if __json['header']['softwareName'] in __excludedSoftwares:
|
if __json['header']['softwareName'] in __excludedSoftwares:
|
||||||
__excluded = True
|
__excluded = True
|
||||||
|
|
||||||
echoLog(' - Software: ' + __json['header']['softwareName'] + ' / ' + __json['header']['softwareVersion'])
|
echoLog(' - Software: ' + __json['header']['softwareName'] + ' / ' + __json['header']['softwareVersion'])
|
||||||
echoLog(' - ' + 'AUTHORISED' if (__authorised == True) else
|
echoLog(' - ' + 'AUTHORISED' if (__authorised == True) else
|
||||||
('EXCLUDED' if (__excluded == True) else 'UNAUTHORISED')
|
('EXCLUDED' if (__excluded == True) else 'UNAUTHORISED')
|
||||||
)
|
)
|
||||||
|
|
||||||
if __authorised == True and __excluded == False:
|
if __authorised == True and __excluded == False:
|
||||||
# Do what you want with the data...
|
# Do what you want with the data...
|
||||||
# Have fun !
|
# Have fun !
|
||||||
|
|
||||||
# For example
|
# For example
|
||||||
echoLog(' - Timestamp: ' + __json['message']['timestamp'])
|
echoLog(' - Timestamp: ' + __json['message']['timestamp'])
|
||||||
echoLog(' - Uploader ID: ' + __json['header']['uploaderID'])
|
echoLog(' - Uploader ID: ' + __json['header']['uploaderID'])
|
||||||
echoLog(' - System Name: ' + __json['message']['systemName'])
|
echoLog(' - System Name: ' + __json['message']['systemName'])
|
||||||
echoLog(' - Station Name: ' + __json['message']['stationName'])
|
echoLog(' - Station Name: ' + __json['message']['stationName'])
|
||||||
|
|
||||||
for __commodity in __json['message']['commodities']:
|
for __commodity in __json['message']['commodities']:
|
||||||
echoLog(' - Name: ' + __commodity['name'])
|
echoLog(' - Name: ' + __commodity['name'])
|
||||||
echoLog(' - Buy Price: ' + str(__commodity['buyPrice']))
|
echoLog(' - Buy Price: ' + str(__commodity['buyPrice']))
|
||||||
echoLog(' - Supply: ' + str(__commodity['supply'])
|
echoLog(' - Supply: ' + str(__commodity['supply'])
|
||||||
+ ((' (' + __commodity['supplyLevel'] + ')') if 'supplyLevel' in __commodity else '')
|
+ ((' (' + __commodity['supplyLevel'] + ')') if 'supplyLevel' in __commodity else '')
|
||||||
)
|
)
|
||||||
echoLog(' - Sell Price: ' + str(__commodity['sellPrice']))
|
echoLog(' - Sell Price: ' + str(__commodity['sellPrice']))
|
||||||
@ -208,18 +208,18 @@ def main():
|
|||||||
+ ((' (' + __commodity['demandLevel'] + ')') if 'demandLevel' in __commodity else '')
|
+ ((' (' + __commodity['demandLevel'] + ')') if 'demandLevel' in __commodity else '')
|
||||||
)
|
)
|
||||||
# End example
|
# End example
|
||||||
|
|
||||||
del __authorised, __excluded
|
del __authorised, __excluded
|
||||||
|
|
||||||
echoLog('')
|
echoLog('')
|
||||||
echoLog('')
|
echoLog('')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
echoLog('Unknown schema: ' + __json['$schemaRef']);
|
echoLog('Unknown schema: ' + __json['$schemaRef']);
|
||||||
|
|
||||||
del __converted
|
del __converted
|
||||||
|
|
||||||
|
|
||||||
except zmq.ZMQError as e:
|
except zmq.ZMQError as e:
|
||||||
echoLog('')
|
echoLog('')
|
||||||
echoLog('ZMQSocketException: ' + str(e))
|
echoLog('ZMQSocketException: ' + str(e))
|
||||||
@ -227,8 +227,8 @@ def main():
|
|||||||
echoLog('Disconnect from ' + __relayEDDN)
|
echoLog('Disconnect from ' + __relayEDDN)
|
||||||
echoLog('')
|
echoLog('')
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user