MCPcopy Create free account
hub / github.com/EDCD/EDDN / main

Function main

examples/Python 2.7/Client_Complete.py:86–215  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

84
85
86def main():
87 echoLog('Starting EDDN Subscriber')
88 echoLog('')
89
90 context = zmq.Context()
91 subscriber = context.socket(zmq.SUB)
92
93 subscriber.setsockopt(zmq.SUBSCRIBE, "")
94 subscriber.setsockopt(zmq.RCVTIMEO, __timeoutEDDN)
95
96 while True:
97 try:
98 subscriber.connect(__relayEDDN)
99 echoLog('Connect to ' + __relayEDDN)
100 echoLog('')
101 echoLog('')
102
103 while True:
104 __message = subscriber.recv()
105
106 if __message == False:
107 subscriber.disconnect(__relayEDDN)
108 echoLog('Disconnect from ' + __relayEDDN)
109 echoLog('')
110 echoLog('')
111 break
112
113 __message = zlib.decompress(__message)
114 __json = simplejson.loads(__message)
115 __converted = False
116
117
118 # Handle commodity v1
119 if __json['$schemaRef'] == 'http://schemas.elite-markets.net/eddn/commodity/1' + ('/test' if (__debugEDDN == True) else ''):
120 echoLogJSON(__message)
121 echoLog('Receiving commodity-v1 message...')
122 echoLog(' - Converting to v2...')
123
124 __temp = {}
125 __temp['$schemaRef'] = 'http://schemas.elite-markets.net/eddn/commodity/2' + ('/test' if (__debugEDDN == True) else '')
126 __temp['header'] = __json['header']
127
128 __temp['message'] = {}
129 __temp['message']['systemName'] = __json['message']['systemName']
130 __temp['message']['stationName'] = __json['message']['stationName']
131 __temp['message']['timestamp'] = __json['message']['timestamp']
132
133 __temp['message']['commodities'] = []
134
135 __commodity = {}
136
137 if 'itemName' in __json['message']:
138 __commodity['name'] = __json['message']['itemName']
139
140 if 'buyPrice' in __json['message']:
141 __commodity['buyPrice'] = __json['message']['buyPrice']
142 if 'stationStock' in __json['message']:
143 __commodity['supply'] = __json['message']['stationStock']

Callers 1

Client_Complete.pyFile · 0.70

Calls 2

echoLogFunction · 0.70
echoLogJSONFunction · 0.70

Tested by

no test coverage detected