15
15
import edce .error
16
16
17
17
testSchema = False
18
+ schemaVersion = 2
18
19
19
20
def convertCategoryEDDN (name ):
20
21
commoditiesCategory = {}
@@ -57,7 +58,7 @@ def submitEDDN(data):
57
58
if r .status_code == requests .codes .ok :
58
59
return r .text
59
60
else :
60
- errstr = "Error: EDDN submitEDDN FAIL %s error: %s" % (r .status_code , r .text )
61
+ errstr = "Status Code %s error: %s" % (r .status_code , r .text )
61
62
raise edce .error .ErrorEDDN (errstr )
62
63
63
64
def getBracket (level ):
@@ -75,75 +76,129 @@ def postMarketData(data):
75
76
76
77
enable = edce .config .getString ('preferences' ,'enable_eddn' )
77
78
if enable .lower () != 'yes' :
78
- errstr = "Error: EDDN postMarketData FAIL, EDDN is disabled in edce.ini"
79
+ errstr = "EDDN is disabled in edce.ini"
79
80
raise edce .error .ErrorEDDN (errstr )
80
81
81
82
username = edce .config .getString ('login' ,'username' )
82
83
if username == '' :
83
- errstr = "Error: EDDN postMarketData FAIL no username"
84
+ errstr = "No username"
84
85
raise edce .error .ErrorEDDN (errstr )
85
86
86
87
if "docked" in data .commander and data .commander .docked :
87
88
pass
88
89
else :
89
- errstr = "Error: EDDN postMarketData FAIL pilot must be docked"
90
+ errstr = "Pilot must be docked"
90
91
raise edce .error .ErrorEDDN (errstr )
91
92
92
93
# Issue 12: No market
93
94
if "commodities" not in data .lastStarport :
94
- errstr = "Error: EDDN postMarketData FAIL station must have a market"
95
+ errstr = "Station must have a market"
95
96
raise edce .error .ErrorEDDN (errstr )
96
97
97
98
try :
98
99
utf8username = edce .util .convertUTF8 (username )
99
100
clientID = hashlib .sha224 (utf8username .encode ('utf-8' )).hexdigest ()
100
-
101
- schema = 'http://schemas.elite-markets.net/eddn/commodity/2'
102
- if testSchema :
103
- schema = schema + '/test'
104
-
105
- message = {}
106
- message ['$schemaRef' ] = schema
107
-
108
- message ['header' ] = {}
109
- message ['header' ]['softwareVersion' ] = edce .globals .version .strip ()
110
- message ['header' ]['softwareName' ] = edce .globals .name .strip ()
111
- message ['header' ]['uploaderID' ] = clientID
112
-
113
- message ['message' ] = {}
114
- message ['message' ]['timestamp' ] = datetime .datetime .utcnow ().isoformat ()
115
- message ['message' ]['systemName' ] = data .lastSystem .name .strip ()
116
- message ['message' ]['stationName' ] = data .lastStarport .name .strip ()
117
-
118
- message ['message' ]['commodities' ] = []
119
-
120
- for commodity in data .lastStarport .commodities :
121
- tmpCommodity = {}
122
-
123
- if "categoryname" in commodity and commodity .categoryname != "NonMarketable" and commodity .stockBracket != '' and commodity .demandBracket != '' :
124
- tmpCommodity ["name" ] = convertCommodityEDDN (commodity .name .strip ()).strip ()
125
-
126
- tmpCommodity ["buyPrice" ] = math .floor (commodity .buyPrice )
127
- tmpCommodity ["sellPrice" ] = math .floor (commodity .sellPrice )
128
-
129
- tmpCommodity ["supply" ] = commodity .stockBracket and math .floor (commodity .stock )
130
- if commodity .stockBracket > 0 :
131
- tmpCommodity ['supplyLevel' ] = getBracket (commodity .stockBracket )
132
-
133
- tmpCommodity ["demand" ] = commodity .demandBracket and math .floor (commodity .demand )
134
- if commodity .demandBracket > 0 :
135
- tmpCommodity ['demandLevel' ] = getBracket (commodity .demandBracket )
136
-
137
- message ['message' ]['commodities' ].append (tmpCommodity )
138
-
139
- else :
140
- if edce .globals .debug :
141
- print (">>>>>>>>>>>>>>>> postMarketData skipped " + commodity .name )
101
+
102
+ if schemaVersion == 2 :
103
+ schema = 'http://schemas.elite-markets.net/eddn/commodity/2'
104
+ if testSchema :
105
+ schema = schema + '/test'
106
+
107
+ if edce .globals .debug :
108
+ print ("Using schema " + schema )
109
+
110
+ message = {}
111
+ message ['$schemaRef' ] = schema
112
+
113
+ message ['header' ] = {}
114
+ message ['header' ]['softwareVersion' ] = edce .globals .version .strip ()
115
+ message ['header' ]['softwareName' ] = edce .globals .name .strip ()
116
+ message ['header' ]['uploaderID' ] = clientID
117
+
118
+ message ['message' ] = {}
119
+ message ['message' ]['timestamp' ] = datetime .datetime .utcnow ().isoformat ()
120
+ message ['message' ]['systemName' ] = data .lastSystem .name .strip ()
121
+ message ['message' ]['stationName' ] = data .lastStarport .name .strip ()
122
+
123
+ message ['message' ]['commodities' ] = []
124
+
125
+ for commodity in data .lastStarport .commodities :
126
+ tmpCommodity = {}
127
+
128
+ if "categoryname" in commodity and commodity .categoryname != "NonMarketable" and commodity .stockBracket != '' and commodity .demandBracket != '' :
129
+ tmpCommodity ["name" ] = convertCommodityEDDN (commodity .name .strip ()).strip ()
142
130
143
- del tmpCommodity
131
+ tmpCommodity ["buyPrice" ] = math .floor (commodity .buyPrice )
132
+ tmpCommodity ["sellPrice" ] = math .floor (commodity .sellPrice )
133
+
134
+ tmpCommodity ["supply" ] = commodity .stockBracket and math .floor (commodity .stock )
135
+ if commodity .stockBracket > 0 :
136
+ tmpCommodity ['supplyLevel' ] = getBracket (commodity .stockBracket )
137
+
138
+ tmpCommodity ["demand" ] = commodity .demandBracket and math .floor (commodity .demand )
139
+ if commodity .demandBracket > 0 :
140
+ tmpCommodity ['demandLevel' ] = getBracket (commodity .demandBracket )
141
+
142
+ message ['message' ]['commodities' ].append (tmpCommodity )
143
+
144
+ else :
145
+ if edce .globals .debug :
146
+ print (">>>>>>>>>>>>>>>> postMarketData skipped " + commodity .name )
147
+
148
+ del tmpCommodity
149
+
150
+ elif schemaVersion == 3 :
151
+ schema = 'http://schemas.elite-markets.net/eddn/commodity/3'
152
+ if testSchema :
153
+ schema = schema + '/test'
154
+
155
+ if edce .globals .debug :
156
+ print ("Using schema " + schema )
157
+
158
+ message = {}
159
+ message ['$schemaRef' ] = schema
160
+
161
+ message ['header' ] = {}
162
+ message ['header' ]['softwareVersion' ] = edce .globals .version .strip ()
163
+ message ['header' ]['softwareName' ] = edce .globals .name .strip ()
164
+ message ['header' ]['uploaderID' ] = clientID
165
+
166
+ message ['message' ] = {}
167
+ message ['message' ]['timestamp' ] = datetime .datetime .utcnow ().isoformat ()
168
+ message ['message' ]['systemName' ] = data .lastSystem .name .strip ()
169
+ message ['message' ]['stationName' ] = data .lastStarport .name .strip ()
144
170
171
+ message ['message' ]['commodities' ] = []
172
+
173
+ for commodity in data .lastStarport .commodities :
174
+ tmpCommodity = {}
175
+
176
+ if "categoryname" in commodity and commodity .categoryname != "NonMarketable" and commodity .stockBracket != '' and commodity .demandBracket != '' :
177
+ tmpCommodity ["name" ] = commodity .name
178
+ tmpCommodity ["meanPrice" ] = commodity .meanPrice
179
+ tmpCommodity ["buyPrice" ] = commodity .buyPrice
180
+ tmpCommodity ["stock" ] = commodity .stock
181
+ tmpCommodity ["stockBracket" ] = commodity .stockBracket
182
+ tmpCommodity ["sellPrice" ] = commodity .sellPrice
183
+ tmpCommodity ["demand" ] = commodity .demand
184
+ tmpCommodity ["demandBracket" ] = commodity .demandBracket
185
+
186
+ if len (commodity .statusFlags ) > 0 :
187
+ tmpCommodity ["statusFlags" ] = commodity .statusFlags
188
+
189
+ message ['message' ]['commodities' ].append (tmpCommodity )
190
+ else :
191
+ if edce .globals .debug :
192
+ print (">>>>>>>>>>>>>>>> postMarketData skipped " + commodity .name )
193
+
194
+ del tmpCommodity
195
+
196
+ else :
197
+ errstr = "Invalid schema version"
198
+ raise edce .error .ErrorEDDN (errstr )
199
+
145
200
submitEDDN (message )
146
201
147
202
except Exception as error :
148
- errstr = "Error: EDDN postMarketData FAIL submit error Reason : %s " % error
203
+ errstr = "Error: EDDN postMarketData FAIL submit error: %s " % error
149
204
raise edce .error .ErrorEDDN (errstr )
0 commit comments