mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-13 07:47:14 +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:
parent
fe3a6c11f4
commit
3a2e159b1e
52
collate.py
52
collate.py
@ -185,34 +185,38 @@ def addships(data):
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) <= 1:
|
||||
print('Usage: collate.py [dump.json]')
|
||||
else:
|
||||
# read from dumped json file(s)
|
||||
session = companion.Session()
|
||||
for f in sys.argv[1:]:
|
||||
with open(f) as h:
|
||||
print(f)
|
||||
data = json.load(h)
|
||||
if not data['commander'].get('docked'):
|
||||
print('Not docked!')
|
||||
sys.exit()
|
||||
|
||||
elif not data.get('lastStarport'):
|
||||
print('No starport!')
|
||||
# read from dumped json file(s)
|
||||
session = companion.Session()
|
||||
for file_name in sys.argv[1:]:
|
||||
data = None
|
||||
with open(file_name) as f:
|
||||
print(file_name)
|
||||
data = json.load(f)
|
||||
|
||||
else:
|
||||
if data['lastStarport'].get('commodities'):
|
||||
addcommodities(data)
|
||||
if not data['commander'].get('docked'):
|
||||
print('Not docked!')
|
||||
continue
|
||||
|
||||
else:
|
||||
print('No market')
|
||||
elif not data.get('lastStarport'):
|
||||
print('No starport!')
|
||||
continue
|
||||
|
||||
if data['lastStarport'].get('modules'):
|
||||
addmodules(data)
|
||||
if data['lastStarport'].get('commodities'):
|
||||
addcommodities(data)
|
||||
|
||||
else:
|
||||
print('No outfitting')
|
||||
else:
|
||||
print('No market')
|
||||
|
||||
if data['lastStarport'].get('ships'):
|
||||
addships(data)
|
||||
if data['lastStarport'].get('modules'):
|
||||
addmodules(data)
|
||||
|
||||
else:
|
||||
print('No shipyard')
|
||||
else:
|
||||
print('No outfitting')
|
||||
|
||||
if data['lastStarport'].get('ships'):
|
||||
addships(data)
|
||||
|
||||
else:
|
||||
print('No shipyard')
|
||||
|
Loading…
x
Reference in New Issue
Block a user