channels.add(channel)
announce[system] = channels
+ async def parse_states(self, data):
+ if 'ActiveStates' in data:
+ return [state['State'] for state in data['ActiveStates']]
+ elif 'FactionState' in data:
+ return [data['FactionState']]
+ else:
+ log.error("Can't find ActiveStates or FactionState in {}".format(data))
+ return ['None']
+
async def update_factions(self, system, factions, iso8601):
- influence = ', '.join(['{} {:.2f}% {}'.format(faction['Name'], faction['Influence'] * 100.0, faction['FactionState']) for faction in reversed(sorted(factions, key = lambda faction: faction['Influence']))])
+ influences = []
+ for faction in reversed(sorted(factions, key = lambda faction: faction['Influence'])):
+ states = await self.parse_states(faction)
+ influences.append('{} {:.2f}% {}'.format(faction['Name'], faction['Influence'] * 100.0, states[0]))
+ influence = ', '.join(influences)
log.debug('{} factions: {}'.format(system, influence))
try:
timestamp = bot.parse_iso8601(iso8601)
trending_states += map(lambda s: (eddb.get_state_id(s['State']), s['Trend'], 'true'), faction['PendingStates'])
if 'RecoveringStates' in faction:
trending_states += map(lambda s: (eddb.get_state_id(s['State']), s['Trend'], 'false'), faction['RecoveringStates'])
- state_id = eddb.get_state_id(faction['FactionState'])
+ active_states = await self.parse_states(faction)
+ state_id = [eddb.get_state_id(state) for state in active_states][0]
if state_id is None:
state_id = eddb.get_state_id('None')
name = faction['Name']