Skip to content

Commit

Permalink
Added consistency check for what to post to EDDN compared to what the…
Browse files Browse the repository at this point in the history
… station should offer.
  • Loading branch information
Bernd Gollesch committed Jul 6, 2016
1 parent 9cfde03 commit 9ce9f87
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions plugins/edapi_plug.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,11 @@ def run(self):
"Station"
)
tdenv.NOTE("{} updated.", csvPath)
station_lookup = tdb.lookupPlace(place)
station_lookup = tdb.lookupStation(station, system)
if not station_lookup:
raise plugins.PluginException(
"Something went wrong while adding the station to the DB."
)
else:
# See if we need to update the info for this station.
print('Station known.')
Expand Down Expand Up @@ -774,15 +777,50 @@ def commodity_int(key):
)
con._debug = False

if len(eddn_market):
def consistencyCheck(checkName, checkList):
warnList = [
"The station should{s} have a {what}, but the API did{d} return one.",
"If you think the DB entry is wrong you can correct it by running:",
" trade.py station -u --{what} {yn} '@{sys}/{stn}'",
]
warnParameter = [
("n't", "", "Y"),
("", "n't", "N"),
]
warnResult = False
checkResult = True

checkAttribute = getattr(station_lookup, checkName)
if len(checkList) > 0:
if checkAttribute == "N":
warnResult = True
checkResult = False
s, d, yn = warnParameter[0]
warnList.append("Ignoring {what}.")
else:
checkResult = False
if checkAttribute == "Y":
warnResult = True
s, d, yn = warnParameter[1]

if warnResult:
for warnText in warnList:
tdenv.WARN(
warnText,
what=checkName, sys=system, stn=station,
s=s, d=d, yn=yn
)
return checkResult

if consistencyCheck("market", eddn_market):
print('Posting commodities to EDDN...')
con.publishCommodities(
system,
station,
eddn_market
)

if len(yardList):
if consistencyCheck("shipyard", yardList):
print('Posting shipyard to EDDN...')
con.publishShipyard(
system,
Expand All @@ -802,7 +840,7 @@ def commodity_int(key):
('bobble', 'decal', 'paintjob')
):
tdenv.NOTE("Unknown module ID: {}, name: {}", module['id'], module['name'])
if len(eddn_modules):
if consistencyCheck("outfitting", eddn_modules):
print('Posting outfitting to EDDN...')
con.publishOutfitting(
system,
Expand Down

0 comments on commit 9ce9f87

Please sign in to comment.