1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-03 00:51:11 +03:00

Refactor __main__ logic

Most of this is just de-pyramiding the code, removing else clauses that
are unneeded (or making the if such that the else is not needed).
Rationale is simple, every level of indentation adds more that the
reader needs to keep track of.
This commit is contained in:
A_D 2020-07-13 06:11:48 +02:00 committed by Athanasius
parent fe3a6c11f4
commit 3a2e159b1e

View File

@ -185,20 +185,24 @@ def addships(data):
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) <= 1: if len(sys.argv) <= 1:
print('Usage: collate.py [dump.json]') print('Usage: collate.py [dump.json]')
else: sys.exit()
# read from dumped json file(s) # read from dumped json file(s)
session = companion.Session() session = companion.Session()
for f in sys.argv[1:]: for file_name in sys.argv[1:]:
with open(f) as h: data = None
print(f) with open(file_name) as f:
data = json.load(h) print(file_name)
data = json.load(f)
if not data['commander'].get('docked'): if not data['commander'].get('docked'):
print('Not docked!') print('Not docked!')
continue
elif not data.get('lastStarport'): elif not data.get('lastStarport'):
print('No starport!') print('No starport!')
continue
else:
if data['lastStarport'].get('commodities'): if data['lastStarport'].get('commodities'):
addcommodities(data) addcommodities(data)