Example #1
0
 def from_corporation(cls, corporation_name, assets=None):
     structure_list = []
     corporation_id = name_to_id(corporation_name, 'corporation')
     assets = assets or Asset.from_entity_id(corporation_id, 'corporations')
     endpoint = 'get_corporations_corporation_id_structures'
     structures_request = esi.op[endpoint](corporation_id=corporation_id)
     structures_response = esi_client.request(structures_request)
     structures = structures_response.data
     endpoint = 'get_corporation_corporation_id_mining_extractions'
     detonations_request = esi.op[endpoint](corporation_id=corporation_id)
     detonations_response = esi_client.request(detonations_request)
     detonations = detonations_response.data
     detonations = {
         d['structure_id']: d['chunk_arrival_time']
         for d in detonations
     }
     structure_keys = [
         'structure_id', 'corporation_id', 'system_id', 'type_id',
         'services', 'fuel_expires', 'state', 'state_timer_end'
     ]
     for s in structures:
         sid = s['structure_id']
         kwargs = {k: v for k, v in s.items() if k in structure_keys}
         kwargs['type_name'] = ids_to_names([s['type_id']])[s['type_id']]
         kwargs['detonation'] = detonations.get(sid)
         structure_contents = [a for a in assets if a.location_id == sid]
         if structure_contents:
             kwargs['fitting'] = Fitting.from_assets(structure_contents)
             kwargs['fuel'] = [
                 a for a in structure_contents
                 if a.location_flag == 'StructureFuel'
             ]
         structure_list.append(cls(**kwargs))
     return structure_list
Example #2
0
 def from_id(cls,
             corp_id,
             starbase_id,
             type_id,
             system_id,
             moon_id,
             state,
             unanchor_at=None,
             reinforced_until=None,
             onlined_since=None,
             mods=[],
             **kwargs):
     pos_data = {
         'item_id': starbase_id,
         'type_id': type_id,
         'location_id': system_id,
         'moon_id': moon_id,
         'state': state,
         'unanchor_at': unanchor_at,
         'reinforced_until': reinforced_until,
         'onlined_since': onlined_since,
         'mods': mods
     }
     op = 'get_corporations_corporation_id_starbases_starbase_id'
     pos_request = esi.op[op](corporation_id=corp_id,
                              starbase_id=starbase_id,
                              system_id=system_id)
     pos_response = esi_client.request(pos_request)
     if pos_response.status == 200:
         pos = pos_response.data
         pos_data.update(pos)
         pos_data.update(kwargs)
         return cls(system_id=system_id, **pos_data)
Example #3
0
 def from_corp_name(corp_name, corp_assets=None):
     pos_mod_dict = {}
     pos_list = []
     corp_assets = corp_assets or Asset.from_entity_name(corp_name)
     assets = [a for a in corp_assets if Pos.is_pos_mod(a)]
     pos_mods = [m for m in assets if m.group.name != 'Control Tower']
     mod_locations = item_locations([m.item_id for m in pos_mods])
     pos_assets = {
         p.item_id: p
         for p in assets if p.group.name == 'Control Tower'
     }
     pos_locations = item_locations(
         [p.item_id for p in pos_assets.values()])
     for mod in pos_mods:
         mod.xyz = mod_locations[mod.item_id]
         mods = pos_mod_dict.setdefault(nearest(mod.xyz, pos_locations), [])
         mods.append(mod)
     corp_id = name_to_id(corp_name, 'corporation')
     poses_request = esi.op['get_corporations_corporation_id_starbases'](
         corporation_id=corp_id)
     poses_response = esi_client.request(poses_request)
     if not poses_response.status == 200:
         raise HTTPError(poses_response.data['error'])
     poses = {s.starbase_id: s for s in poses_response.data}
     for pos_id, pos in poses.iteritems():
         pos.update(pos_assets[pos.starbase_id].__dict__)
         pos['xyz'] = pos_locations[pos.starbase_id]
         pos_object = Pos.from_id(corp_id=corp_id,
                                  mods=pos_mod_dict.get(pos_id, []),
                                  **pos)
         pos_list.append(pos_object)
     return pos_list
Example #4
0
 def moon_name(self):
     try:
         return self._moon_name
     except AttributeError:
         moon_name_request = esi.op['get_universe_moons_moon_id'](
             moon_id=self.moon_id)
         moon_name_response = esi_client.request(moon_name_request)
         if moon_name_response.status == 200:
             self._moon_name = moon_name_response.data.get('name')
         return self._moon_name
Example #5
0
 def system_name(self):
     try:
         return self._system_name
     except AttributeError:
         self._system_name = None
         location_name_request = esi.op['get_universe_systems_system_id'](
             system_id=self.system_id)
         location_name_response = esi_client.request(location_name_request)
         if location_name_response.status == 200:
             self._system_name = location_name_response.data.get('name')
         return self._system_name
Example #6
0
 def __init__(self,
              structure_id,
              corporation_id=None,
              type_id=None,
              type_name=None,
              system_id=None,
              services=None,
              fuel_expires=None,
              accessible=None,
              name=None,
              state=None,
              state_timer_end=None,
              detonation=None,
              fuel=[],
              fitting=Fitting()):
     super(Structure, self).__init__()
     self.structure_id = structure_id
     self.corporation_id = corporation_id
     self.type_id = type_id
     self.type = Type.from_id(type_id)
     self.type_name = type_name
     self.system_id = system_id
     self.fuel = fuel
     self.fuel_expires = getattr(fuel_expires, 'v', None)
     self.accessible = accessible
     self.name = name
     self.state = state
     self.state_timer_end = getattr(state_timer_end, 'v', None)
     self.detonation = getattr(detonation, 'v', None)
     self.fitting = fitting
     self._fuel_rate = 0
     # Grab structure name
     endpoint = 'get_universe_structures_structure_id'
     structure_request = esi.op[endpoint](structure_id=structure_id)
     structure_response = esi_client.request(structure_request)
     if structure_response.status == 200:
         structure_info = structure_response.data
         self.name = structure_info.get('name')
         self.system_id = structure_info.get('system_id')
         self.type_id = structure_info.get('type_id')
         self.accessible = True
     elif structure_response.status == 403:
         self.name = "Inaccessible Structure"
         self.accessible = False
     self.online_services = []
     self.offline_services = []
     if services:
         for service in services:
             if service['state'] == 'online':
                 self.online_services.append(service.get('name'))
             if service['state'] == 'offline':
                 self.offline_services.append(service.get('name'))
Example #7
0
def sov_systems(sov_holder_id):
    """Returns a list of system IDs held by sov holder

    Args:
        sov_holder_id (int): Alliance ID

    Returns:
        list: List of system ID (int) held by sov holder
    """
    sov_systems = []
    if sov_holder_id:
        map_sov_request = esi.op['get_sovereignty_map']()
        map_sov = esi_client.request(map_sov_request).data
        for system in map_sov:
            try:
                if system.get('alliance_id', 0) == sov_holder_id:
                    sov_systems.append(system['system_id'])
            except KeyError:
                continue
    return sov_systems
Example #8
0
def item_locations(ids):
    """Returns dict of location coordinates for a list of item ids

    Args:
        ids (list): list of item ids

    Returns:
        dict: dict of location coordinates keyed by item id
    """
    location_dict = {}
    chunks = 1000
    for items in [ids[i:i + chunks] for i in range(0, len(ids), chunks)]:
        op = 'post_corporations_corporation_id_assets_locations'
        locations_request = esi.op[op](item_ids=items,
                                       corporation_id=CONFIG['CORP_ID'])
        locations = esi_client.request(locations_request).data
        for location in locations:
            i = int(location.get('item_id'))
            location_dict[i] = location.position
    return location_dict
Example #9
0
def check_pos(corp_name, corp_assets=None):
    """
    Check POS for fuel and status
    
    Returns:
        list: list of alert strings

    """
    messages = []
    corp_id = name_to_id(CONFIG['CORPORATION_NAME'], 'corporation')
    pos_list = Pos.from_corp_name(corp_name, corp_assets)
    if not pos_list:
        return messages
    alliance_id_request = esi.op['get_corporations_corporation_id'](
        corporation_id=corp_id)
    alliance_id = esi_client.request(alliance_id_request).data.get(
        'alliance_id', None)
    sovs = sov_systems(alliance_id)
    for pos in pos_list:
        # TODO: All this could be done in the Pos object for easier testing
        # But POS are going away ;)
        sov = pos.system_id in sovs
        has_stront = False
        has_fuel = False
        has_defensive_mods = False
        for fuel in pos.fuels:
            multiplier = .75 if sov else 1.0
            rate = pos_fuel[pos.type_id][fuel.type_id] * multiplier
            if fuel.type_id == 16275:
                has_stront = True
                if pos.state == 'offline':
                    continue
                reinforce_hours = int(fuel.quantity / rate)
                if reinforce_hours < CONFIG['STRONT_HOURS']:
                    message = '{} has {} hours of stront'.format(
                        pos.moon_name, reinforce_hours)
                    messages.append(message)
            else:
                has_fuel = True
                if pos.state == 'offline':
                    continue
                how_soon = datetime.timedelta(fuel.quantity / (rate * 24))
                if how_soon < CONFIG['TOO_SOON']:
                    days = 'day' if how_soon == 1 else 'days'
                    message = '{} has {} {} of fuel'.format(
                        pos.moon_name, how_soon, days)
                    messages.append(message)
        for mod in pos.mods:
            if mod.group.name == 'Shield Hardening Array':
                has_defensive_mods = True
        if pos.state != 'online':
            if has_fuel and pos.state == 'offline' and not has_defensive_mods:
                continue
            message = '{} is {}'.format(pos.moon_name, pos.state)
            if pos.reinforced_until:
                state_predicates = {'reinforced': 'until'}
                message += ' {} {}'.format(
                    state_predicates.get(pos.state, 'since'),
                    pos.reinforced_until)
            messages.append(message)
    return messages