From 8f0d063e79399bd8af052cfede04d9b5de4585c2 Mon Sep 17 00:00:00 2001 From: AnthorNet Date: Wed, 29 Apr 2015 16:15:19 +0200 Subject: [PATCH 1/4] Add debug mode --- examples/PHP/Client.php | 14 +++++++++----- examples/Python/Client.py | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/examples/PHP/Client.php b/examples/PHP/Client.php index 55828d1..5fe55bf 100644 --- a/examples/PHP/Client.php +++ b/examples/PHP/Client.php @@ -5,6 +5,9 @@ $relayEDDN = 'tcp://eddn-relay.elite-markets.net:9500'; $timeoutEDDN = 600000; +// Set false to listen to production stream +$debugEDDN = true; + // Set to false if you do not want verbose logging $logVerboseFile = dirname(__FILE__) . '/Logs_Verbose_EDDN_%DATE%.htm'; //$logVerboseFile = false; @@ -15,11 +18,12 @@ $logJSONFile = dirname(__FILE__) . '/Logs_JSON_EDDN_%DATE%.log'; // A sample list of authorised softwares $authorisedSoftwares = array( + "EDCE", "ED-TD.SPACE", "EliteOCR", + "Maddavo's Market Share", "RegulatedNoise", - "RegulatedNoise__DJ", - "Maddavo's Market Share" + "RegulatedNoise__DJ" ); // Used this to excludes yourself for example has you don't want to handle your own messages ^^ @@ -115,14 +119,14 @@ while (true) $converted = false; // Handle commodity v1 - if($json['$schemaRef'] == 'http://schemas.elite-markets.net/eddn/commodity/1') + if($json['$schemaRef'] == 'http://schemas.elite-markets.net/eddn/commodity/1' . (($debugEDDN === true) ? '/test' : '')) { echoLogJSON($message); echoLog('Receiving commodity-v1 message...'); echoLog(' - Converting to v2...'); $temp = array(); - $temp['$schemaRef'] = 'http://schemas.elite-markets.net/eddn/commodity/2'; + $temp['$schemaRef'] = 'http://schemas.elite-markets.net/eddn/commodity/2' . (($debugEDDN === true) ? '/test' : ''); $temp['header'] = $json['header']; $temp['message'] = array(); @@ -160,7 +164,7 @@ while (true) // Handle commodity v2 - if($json['$schemaRef'] == 'http://schemas.elite-markets.net/eddn/commodity/2') + if($json['$schemaRef'] == 'http://schemas.elite-markets.net/eddn/commodity/2' . (($debugEDDN === true) ? '/test' : '')) { if($converted === false) { diff --git a/examples/Python/Client.py b/examples/Python/Client.py index 45b89cf..f4e215b 100644 --- a/examples/Python/Client.py +++ b/examples/Python/Client.py @@ -9,6 +9,9 @@ import sys, os, datetime, time __relayEDDN = 'tcp://eddn-relay.elite-markets.net:9500' __timeoutEDDN = 600000 +# Set False to listen to production stream +__debugEDDN = True; + # Set to False if you do not want verbose logging __logVerboseFile = os.path.dirname(__file__) + '/Logs_Verbose_EDDN_%DATE%.htm' #__logVerboseFile = False @@ -19,11 +22,12 @@ __logJSONFile = os.path.dirname(__file__) + '/Logs_JSON_EDDN_%DATE%.lo # A sample list of authorised softwares __authorisedSoftwares = [ + "EDCE", "ED-TD.SPACE", "EliteOCR", + "Maddavo's Market Share", "RegulatedNoise", - "RegulatedNoise__DJ", - "Maddavo's Market Share" + "RegulatedNoise__DJ" ] # Used this to excludes yourself for example has you don't want to handle your own messages ^^ @@ -106,13 +110,13 @@ def main(): # Handle commodity v1 - if __json['$schemaRef'] == 'http://schemas.elite-markets.net/eddn/commodity/1': + if __json['$schemaRef'] == 'http://schemas.elite-markets.net/eddn/commodity/1' + ('/test' if (__debugEDDN == True) else ''): echoLogJSON(__message) echoLog('Receiving commodity-v1 message...'); echoLog(' - Converting to v2...'); __temp = {} - __temp['$schemaRef'] = 'http://schemas.elite-markets.net/eddn/commodity/2' + __temp['$schemaRef'] = 'http://schemas.elite-markets.net/eddn/commodity/2' + ('/test' if (__debugEDDN == True) else '') __temp['header'] = __json['header'] __temp['message'] = {} @@ -148,7 +152,7 @@ def main(): __converted = True # Handle commodity v2 - if __json['$schemaRef'] == 'http://schemas.elite-markets.net/eddn/commodity/2': + if __json['$schemaRef'] == 'http://schemas.elite-markets.net/eddn/commodity/2' + ('/test' if (__debugEDDN == True) else ''): if __converted == False: echoLogJSON(__message) echoLog('Receiving commodity-v2 message...') From 04700c1441d52735f786241eb17c19987e016504 Mon Sep 17 00:00:00 2001 From: AnthorNet Date: Wed, 29 Apr 2015 16:19:36 +0200 Subject: [PATCH 2/4] Fix empty log lines on verbose --- examples/PHP/Client.php | 5 +++-- examples/Python/Client.py | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/PHP/Client.php b/examples/PHP/Client.php index 5fe55bf..e0abbfb 100644 --- a/examples/PHP/Client.php +++ b/examples/PHP/Client.php @@ -212,11 +212,12 @@ while (true) } unset($authorised, $excluded); + + echoLog(''); + echoLog(''); } unset($converted); - echoLog(''); - echoLog(''); } } catch (ZMQSocketException $e) diff --git a/examples/Python/Client.py b/examples/Python/Client.py index f4e215b..d552df4 100644 --- a/examples/Python/Client.py +++ b/examples/Python/Client.py @@ -191,12 +191,12 @@ def main(): ) # End example - del __authorised, __excluded + + echoLog('') + echoLog('') del __converted - echoLog('') - echoLog('') except zmq.ZMQError, e: From d12dd9c00a21464b2bf75cd26cd429e853526bb1 Mon Sep 17 00:00:00 2001 From: AnthorNet Date: Wed, 29 Apr 2015 16:29:11 +0200 Subject: [PATCH 3/4] Add uploadID in verbose logs --- examples/PHP/Client.php | 1 + examples/Python/Client.py | 1 + 2 files changed, 2 insertions(+) diff --git a/examples/PHP/Client.php b/examples/PHP/Client.php index e0abbfb..6237467 100644 --- a/examples/PHP/Client.php +++ b/examples/PHP/Client.php @@ -193,6 +193,7 @@ while (true) // For example echoLog(' - Timestamp: ' . $json['message']['timestamp']); + echoLog(' - Uploader ID: ' . $json['header']['uploaderID']); echoLog(' - System Name: ' . $json['message']['systemName']); echoLog(' - Station Name: ' . $json['message']['stationName']); diff --git a/examples/Python/Client.py b/examples/Python/Client.py index d552df4..734c318 100644 --- a/examples/Python/Client.py +++ b/examples/Python/Client.py @@ -176,6 +176,7 @@ def main(): # For example echoLog(' - Timestamp: ' + __json['message']['timestamp']) + echoLog(' - Uploader ID: ' + __json['header']['uploaderID']) echoLog(' - System Name: ' + __json['message']['systemName']) echoLog(' - Station Name: ' + __json['message']['stationName']) From 557b70d81ba22385cfd12d8b517c2466c58867ec Mon Sep 17 00:00:00 2001 From: AnthorNet Date: Mon, 4 May 2015 10:12:10 +0200 Subject: [PATCH 4/4] Add simple and complete example to Python --- examples/Python/Client.bat | 3 -- examples/Python/Client_Complete.bat | 3 ++ .../Python/{Client.py => Client_Complete.py} | 0 examples/Python/Client_Simple.bat | 3 ++ examples/Python/Client_Simple.py | 49 +++++++++++++++++++ 5 files changed, 55 insertions(+), 3 deletions(-) delete mode 100644 examples/Python/Client.bat create mode 100644 examples/Python/Client_Complete.bat rename examples/Python/{Client.py => Client_Complete.py} (100%) create mode 100644 examples/Python/Client_Simple.bat create mode 100644 examples/Python/Client_Simple.py diff --git a/examples/Python/Client.bat b/examples/Python/Client.bat deleted file mode 100644 index f8b5331..0000000 --- a/examples/Python/Client.bat +++ /dev/null @@ -1,3 +0,0 @@ -"python" %~dp0\Client.py - -pause \ No newline at end of file diff --git a/examples/Python/Client_Complete.bat b/examples/Python/Client_Complete.bat new file mode 100644 index 0000000..1801683 --- /dev/null +++ b/examples/Python/Client_Complete.bat @@ -0,0 +1,3 @@ +"python" %~dp0\Client_Complete.py + +pause \ No newline at end of file diff --git a/examples/Python/Client.py b/examples/Python/Client_Complete.py similarity index 100% rename from examples/Python/Client.py rename to examples/Python/Client_Complete.py diff --git a/examples/Python/Client_Simple.bat b/examples/Python/Client_Simple.bat new file mode 100644 index 0000000..6991101 --- /dev/null +++ b/examples/Python/Client_Simple.bat @@ -0,0 +1,3 @@ +"python" %~dp0\Client_Simple.py + +pause \ No newline at end of file diff --git a/examples/Python/Client_Simple.py b/examples/Python/Client_Simple.py new file mode 100644 index 0000000..74afe3a --- /dev/null +++ b/examples/Python/Client_Simple.py @@ -0,0 +1,49 @@ +import zlib +import zmq.green as zmq +import simplejson +import sys + +""" + " Configuration +""" +__relayEDDN = 'tcp://eddn-relay.elite-markets.net:9500' +__timeoutEDDN = 600000 + + +""" + " Start +""" +def main(): + context = zmq.Context() + subscriber = context.socket(zmq.SUB) + + subscriber.setsockopt(zmq.SUBSCRIBE, "") + subscriber.setsockopt(zmq.RCVTIMEO, __timeoutEDDN) + + while True: + try: + subscriber.connect(__relayEDDN) + + while True: + __message = subscriber.recv() + + if __message == False: + subscriber.disconnect(__relayEDDN) + break + + __message = zlib.decompress(__message) + __json = simplejson.loads(__message) + + + print __json + sys.stdout.flush() + + except zmq.ZMQError, e: + print 'ZMQSocketException: ' + str(e) + sys.stdout.flush() + time.sleep(10) + + + +if __name__ == '__main__': + main()