MCPcopy
hub / github.com/pyfa-org/Pyfa / exportESI

Function exportESI

service/port/esi.py:59–160  ·  view source on GitHub ↗
(ofit, exportCharges, exportImplants, exportBoosters, callback)

Source from the content-addressed store, hash-verified

57
58
59def exportESI(ofit, exportCharges, exportImplants, exportBoosters, callback):
60 # A few notes:
61 # max fit name length is 50 characters
62 # Most keys are created simply because they are required, but bogus data is okay
63
64 nested_dict = lambda: defaultdict(nested_dict)
65 fit = nested_dict()
66 sFit = svcFit.getInstance()
67
68 # max length is 50 characters
69 name = ofit.name[:47] + '...' if len(ofit.name) > 50 else ofit.name
70 fit['name'] = name
71 fit['ship_type_id'] = ofit.ship.item.ID
72
73 # 2017/03/29 NOTE: "<" or "&lt;" is Ignored
74 # fit['description'] = "<pyfa:%d />" % ofit.ID
75 fit['description'] = "" if ofit.notes is None else ofit.notes[:397] + '...' if len(ofit.notes) > 400 else ofit.notes
76 fit['items'] = []
77
78 slotNum = {}
79 charges = {}
80 for module in ofit.modules:
81 if module.isEmpty:
82 continue
83
84 item = nested_dict()
85 slot = module.slot
86
87 if slot == FittingSlot.SUBSYSTEM:
88 # Order of subsystem matters based on this attr. See GH issue #130
89 slot = int(module.getModifiedItemAttr("subSystemSlot"))
90 item['flag'] = slot
91 else:
92 if slot not in slotNum:
93 slotNum[slot] = INV_FLAGS[slot]
94
95 item['flag'] = slotNum[slot]
96 slotNum[slot] += 1
97
98 item['quantity'] = 1
99 item['type_id'] = module.item.ID
100 fit['items'].append(item)
101
102 if module.charge and exportCharges:
103 if module.chargeID not in charges:
104 charges[module.chargeID] = 0
105 # `or 1` because some charges (ie scripts) are without qty
106 charges[module.chargeID] += module.numCharges or 1
107
108 for cargo in ofit.cargo:
109 item = nested_dict()
110 item['flag'] = INV_FLAG_CARGOBAY
111 item['quantity'] = cargo.amount
112 item['type_id'] = cargo.item.ID
113 fit['items'].append(item)
114
115 for chargeID, amount in list(charges.items()):
116 item = nested_dict()

Callers 1

exportESIMethod · 0.90

Calls 5

ESIExportExceptionClass · 0.85
itemsMethod · 0.80
getInstanceMethod · 0.45
getModifiedItemAttrMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected