def get_sell_prices(item_ids, systemID): prices = {} for some_ids in tools.sublists(item_ids, 50): params = [("typeid", type_id) for type_id in some_ids] if systemID != 1: params.append(("usesystem", systemID)) evecentralurl = Setting.get('industry_evecentral_url') url = evecentralurl + '?' + urllib.urlencode(params) try: response = urllib2.urlopen(url) except (URLError, HTTPError), err: LOG.warning(str(err)) continue element = ElementTree.parse(source=response) for typ in element.findall('.//type'): typeID = int(typ.attrib['id']) buyMax = typ.find('sell/min') if buyMax is not None: prices[typeID] = round(float(buyMax.text), 2)
def get_sell_prices(item_ids, systemID): prices = {} for some_ids in tools.sublists(item_ids, 50): params = [ ("typeid", type_id) for type_id in some_ids ] if systemID != 1: params.append(("usesystem", systemID)) evecentralurl = Setting.get('industry_evecentral_url') url = evecentralurl + '?' + urllib.urlencode(params) try: response = urllib2.urlopen(url) except (URLError, HTTPError), err: LOG.warning(str(err)) continue element = ElementTree.parse(source=response) for typ in element.findall('.//type'): typeID = int(typ.attrib['id']) buyMax = typ.find('sell/min') if buyMax is not None: prices[typeID] = round(float(buyMax.text), 2)
def update_assets_names(): LOG.debug('Updating player defined names...') assets_to_name = Asset.objects.filter(name=None, container1=None, container2=None, singleton=True, hasContents=True, quantity=1).values_list('itemID', flat=True) api_conn = api.connect() named_assets = [] # Fetch all the x,y,z positions of the assets from the API for sub_list in tools.sublists(assets_to_name, sub_length=50): # max 50 items per request LOG.debug('fetching /corp/Locations.xml.aspx...') ids = ','.join(map(str, sub_list)) try: locations_api = api_conn.corp.Locations( characterID=api.get_charID(), ids=ids) for loc in locations_api.locations: named_assets.append((loc.itemID, loc.itemName)) except api.Error, err: # error can happen if a ship/asset found in a SMA/CHA does not belong to the corp LOG.warning( '%s (code %s). Item IDs: %s (names will not be retrieved for these items).', err.code, str(err), ids)
def get_mail(api_conn, char): headers = api_conn.char.MailMessages(characterID=char.characterID) headerlist = [] for head in headers.messages: if Mail.objects.filter(messageID=head.messageID): continue headerlist.append(head.messageID) mail = Mail() mail.messageID = head.messageID try: mem = Member.objects.get(characterID=head.senderID) except Member.DoesNotExist: mem = get_char(head.senderID) mail.sender = mem mail.sentDate = timezone.make_aware(head.sentDate, timezone.utc) mail.title = head.title mail.save() if not head.toCorpOrAllianceID == '': rec = Recipient() rec.mail = mail rec.recipient = get_corp_or_alliance(head.toCorpOrAllianceID) rec.save() for chid in str(head.toCharacterIDs).split(','): if chid == '': break try: mem = Member.objects.get(characterID=int(chid)) except Member.DoesNotExist: mem = get_char(chid) rec = Recipient() rec.mail = mail rec.recipient = mem rec.save() if head.toListID: try: lis = MailingList.objects.get(listID=head.toListID) except MailingList.DoesNotExist: lis = MailingList() lis.listID = head.toListID lis.displayName = "Unknown Mailing List" lis.save() rec = Recipient() rec.mail = mail rec.recipient = lis rec.save() #Get Message Body if not headerlist == []: for sub_list in tools.sublists(headerlist, sub_length=50): bodies = api_conn.char.MailBodies(characterID=char.characterID, ids=sub_list) for body in bodies.messages: msg = Mail.objects.get(messageID=body.messageID) msg.body = body.data msg.save() logger.info('Char: %s added %s mails' % (char.name, len(headerlist)))
def get_mail(api_conn, char): headers = api_conn.char.MailMessages(characterID=char.characterID) headerlist = [] for head in headers.messages: if Mail.objects.filter(messageID=head.messageID): continue headerlist.append(head.messageID) mail = Mail() mail.messageID = head.messageID try: mem = Member.objects.get(characterID = head.senderID) except Member.DoesNotExist: mem = get_char(head.senderID) mail.sender = mem mail.sentDate = timezone.make_aware(head.sentDate, timezone.utc) mail.title = head.title mail.save() if not head.toCorpOrAllianceID == '': rec = Recipient() rec.mail = mail rec.recipient = get_corp_or_alliance(head.toCorpOrAllianceID) rec.save() for chid in str(head.toCharacterIDs).split(','): if chid == '': break try: mem = Member.objects.get(characterID = int(chid)) except Member.DoesNotExist: mem = get_char(chid) rec = Recipient() rec.mail = mail rec.recipient = mem rec.save() if head.toListID: try: lis = MailingList.objects.get(listID=head.toListID) except MailingList.DoesNotExist: lis = MailingList() lis.listID = head.toListID lis.displayName = "Unknown Mailing List" lis.save() rec = Recipient() rec.mail = mail rec.recipient = lis rec.save() #Get Message Body if not headerlist == []: for sub_list in tools.sublists(headerlist, sub_length=50): bodies = api_conn.char.MailBodies(characterID = char.characterID, ids = sub_list) for body in bodies.messages: msg = Mail.objects.get(messageID = body.messageID) msg.body = body.data msg.save() logger.info('Char: %s added %s mails'%(char.name,len(headerlist)))
def update_assets_locations(assets_to_locate): LOG.debug('Locating assets to their closest celestial object...') api_conn = api.connect() located_assets = [] # Fetch all the x,y,z positions of the assets from the API for sub_list in tools.sublists(assets_to_locate, sub_length=50): # max 50 items per request LOG.debug('fetching /corp/Locations.xml.aspx...') ids = ','.join(map(str, sub_list)) try: locations_api = api_conn.corp.Locations(characterID=api.get_charID(), ids=ids) for loc in locations_api.locations: located_assets.append((loc.itemID, loc.itemName, loc.x, loc.y, loc.z)) except api.Error, err: # error can happen if a ship/asset found in a SMA/CHA does not belong to the corp LOG.warning('%s (code %s). Item IDs: %s (names will not be retrieved for these items).', err.code, str(err), ids)
def create_missing_catalog_entries(): start = time.time() manufacturable_types = Type.objects.filter(blueprint__isnull=False, published=1, metaGroupID__in=constants.MANUFACTURABLE_ITEMS, market_group__isnull=False) manufacturable_types = manufacturable_types.exclude(typeID__in=constants.FACTION_FRIGATES_TYPEIDS) eve_typeIDs = set(manufacturable_types.values_list('typeID', flat=True)) ecm_typeIDs = set(CatalogEntry.objects.values_list('typeID', flat=True)) missing_ids = list(eve_typeIDs - ecm_typeIDs) for sublist in tools.sublists(missing_ids, 50): for obj in Type.objects.filter(typeID__in=sublist): CatalogEntry.objects.create(typeID=obj.typeID, typeName=obj.typeName, is_available=False) if missing_ids: duration = time.time() - start logger.info('added %d missing catalog entries (took %.2f sec.)', len(missing_ids), duration)
def update_assets_locations(assets_to_locate): LOG.debug('Locating assets to their closest celestial object...') api_conn = api.connect() located_assets = [] # Fetch all the x,y,z positions of the assets from the API for sub_list in tools.sublists(assets_to_locate, sub_length=50): # max 50 items per request LOG.debug('fetching /corp/Locations.xml.aspx...') ids = ','.join(map(str, sub_list)) try: locations_api = api_conn.corp.Locations( characterID=api.get_charID(), ids=ids) for loc in locations_api.locations: located_assets.append( (loc.itemID, loc.itemName, loc.x, loc.y, loc.z)) except api.Error, err: # error can happen if a ship/asset found in a SMA/CHA does not belong to the corp LOG.warning( '%s (code %s). Item IDs: %s (names will not be retrieved for these items).', err.code, str(err), ids)
def update_assets_names(): LOG.debug('Updating player defined names...') assets_to_name = Asset.objects.filter(name=None, container1=None, container2=None, singleton=True, hasContents=True, quantity=1).values_list('itemID', flat=True) api_conn = api.connect() named_assets = [] # Fetch all the x,y,z positions of the assets from the API for sub_list in tools.sublists(assets_to_name, sub_length=50): # max 50 items per request LOG.debug('fetching /corp/Locations.xml.aspx...') ids = ','.join(map(str, sub_list)) try: locations_api = api_conn.corp.Locations(characterID=api.get_charID(), ids=ids) for loc in locations_api.locations: named_assets.append((loc.itemID, loc.itemName)) except api.Error, err: # error can happen if a ship/asset found in a SMA/CHA does not belong to the corp LOG.warning('%s (code %s). Item IDs: %s (names will not be retrieved for these items).', err.code, str(err), ids)
def create_missing_catalog_entries(): start = time.time() manufacturable_types = Type.objects.filter( blueprint__isnull=False, published=1, metaGroupID__in=constants.MANUFACTURABLE_ITEMS, market_group__isnull=False) manufacturable_types = manufacturable_types.exclude( typeID__in=constants.FACTION_FRIGATES_TYPEIDS) eve_typeIDs = set(manufacturable_types.values_list('typeID', flat=True)) ecm_typeIDs = set(CatalogEntry.objects.values_list('typeID', flat=True)) missing_ids = list(eve_typeIDs - ecm_typeIDs) for sublist in tools.sublists(missing_ids, 50): for obj in Type.objects.filter(typeID__in=sublist): CatalogEntry.objects.create(typeID=obj.typeID, typeName=obj.typeName, is_available=False) if missing_ids: duration = time.time() - start logger.info('added %d missing catalog entries (took %.2f sec.)', len(missing_ids), duration)
def create_missing_item_groups(): start = time.time() all_types = Type.objects.filter(blueprint__isnull=False, published=1, metaGroupID__in=constants.MANUFACTURABLE_ITEMS, market_group__isnull=False) all_types = all_types.exclude(typeID__in=constants.FACTION_FRIGATES_TYPEIDS) t1_items_group, _ = ItemGroup.objects.get_or_create(name='Tech 1 Items') t2_items_group, _ = ItemGroup.objects.get_or_create(name='Tech 2 Items') t3_items_group, _ = ItemGroup.objects.get_or_create(name='Tech 3 Items') t1_ships_group, _ = ItemGroup.objects.get_or_create(name='Tech 1 Ships') t2_ships_group, _ = ItemGroup.objects.get_or_create(name='Tech 2 Ships') t3_ships_group, _ = ItemGroup.objects.get_or_create(name='Tech 3 Ships') t1_modules_group, _ = ItemGroup.objects.get_or_create(name='Tech 1 Modules') t2_modules_group, _ = ItemGroup.objects.get_or_create(name='Tech 2 Modules') t3_modules_group, _ = ItemGroup.objects.get_or_create(name='Tech 3 Modules') charges_group, _ = ItemGroup.objects.get_or_create(name='Charges') capital_ships_group, _ = ItemGroup.objects.get_or_create(name='Capital Ships') t1_items = all_types.filter(techLevel=1) t2_items = all_types.filter(techLevel=2) t3_items = all_types.filter(techLevel=3) t1_ships = t1_items.filter(category=constants.SHIP_CATEGORYID) t2_ships = t2_items.filter(category=constants.SHIP_CATEGORYID) t3_ships = t3_items.filter(category=constants.SHIP_CATEGORYID) t1_modules = t1_items.filter(category=constants.MODULE_CATEGORYID) t2_modules = t2_items.filter(category=constants.MODULE_CATEGORYID) t3_modules = t3_items.filter(category=constants.MODULE_CATEGORYID) charges = all_types.filter(category=constants.CHARGE_CATEGORYID) capital_ships = all_types.filter(group__in=constants.CAPITAL_SHIPS_GROUPID) for ids in tools.sublists(list(t1_items.values_list('typeID', flat=True)), 200): t1_items_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) for ids in tools.sublists(list(t2_items.values_list('typeID', flat=True)), 200): t2_items_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) for ids in tools.sublists(list(t3_items.values_list('typeID', flat=True)), 200): t3_items_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) for ids in tools.sublists(list(t1_ships.values_list('typeID', flat=True)), 200): t1_ships_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) for ids in tools.sublists(list(t2_ships.values_list('typeID', flat=True)), 200): t2_ships_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) for ids in tools.sublists(list(t3_ships.values_list('typeID', flat=True)), 200): t3_ships_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) for ids in tools.sublists(list(t1_modules.values_list('typeID', flat=True)), 200): t1_modules_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) for ids in tools.sublists(list(t2_modules.values_list('typeID', flat=True)), 200): t2_modules_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) for ids in tools.sublists(list(t3_modules.values_list('typeID', flat=True)), 200): t3_modules_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) for ids in tools.sublists(list(charges.values_list('typeID', flat=True)), 200): charges_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) for ids in tools.sublists(list(capital_ships.values_list('typeID', flat=True)), 200): capital_ships_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) duration = time.time() - start logger.info('Initialized item groups (took %.2f sec.)', duration)
def create_missing_item_groups(): start = time.time() all_types = Type.objects.filter( blueprint__isnull=False, published=1, metaGroupID__in=constants.MANUFACTURABLE_ITEMS, market_group__isnull=False) all_types = all_types.exclude( typeID__in=constants.FACTION_FRIGATES_TYPEIDS) t1_items_group, _ = ItemGroup.objects.get_or_create(name='Tech 1 Items') t2_items_group, _ = ItemGroup.objects.get_or_create(name='Tech 2 Items') t3_items_group, _ = ItemGroup.objects.get_or_create(name='Tech 3 Items') t1_ships_group, _ = ItemGroup.objects.get_or_create(name='Tech 1 Ships') t2_ships_group, _ = ItemGroup.objects.get_or_create(name='Tech 2 Ships') t3_ships_group, _ = ItemGroup.objects.get_or_create(name='Tech 3 Ships') t1_modules_group, _ = ItemGroup.objects.get_or_create( name='Tech 1 Modules') t2_modules_group, _ = ItemGroup.objects.get_or_create( name='Tech 2 Modules') t3_modules_group, _ = ItemGroup.objects.get_or_create( name='Tech 3 Modules') charges_group, _ = ItemGroup.objects.get_or_create(name='Charges') capital_ships_group, _ = ItemGroup.objects.get_or_create( name='Capital Ships') t1_items = all_types.filter(metaGroupID=1) t2_items = all_types.filter(metaGroupID=2) t3_items = all_types.filter(metaGroupID=14) # T3 metaGroup is 14 t1_ships = t1_items.filter(category=constants.SHIP_CATEGORYID) t2_ships = t2_items.filter(category=constants.SHIP_CATEGORYID) t3_ships = t3_items.filter(category=constants.SHIP_CATEGORYID) t1_modules = t1_items.filter(category=constants.MODULE_CATEGORYID) t2_modules = t2_items.filter(category=constants.MODULE_CATEGORYID) t3_modules = t3_items.filter(category=constants.MODULE_CATEGORYID) charges = all_types.filter(category=constants.CHARGE_CATEGORYID) capital_ships = all_types.filter(group__in=constants.CAPITAL_SHIPS_GROUPID) for ids in tools.sublists(list(t1_items.values_list('typeID', flat=True)), 200): t1_items_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) for ids in tools.sublists(list(t2_items.values_list('typeID', flat=True)), 200): t2_items_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) for ids in tools.sublists(list(t3_items.values_list('typeID', flat=True)), 200): t3_items_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) for ids in tools.sublists(list(t1_ships.values_list('typeID', flat=True)), 200): t1_ships_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) for ids in tools.sublists(list(t2_ships.values_list('typeID', flat=True)), 200): t2_ships_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) for ids in tools.sublists(list(t3_ships.values_list('typeID', flat=True)), 200): t3_ships_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) for ids in tools.sublists( list(t1_modules.values_list('typeID', flat=True)), 200): t1_modules_group.items.add(*CatalogEntry.objects.filter( typeID__in=ids)) for ids in tools.sublists( list(t2_modules.values_list('typeID', flat=True)), 200): t2_modules_group.items.add(*CatalogEntry.objects.filter( typeID__in=ids)) for ids in tools.sublists( list(t3_modules.values_list('typeID', flat=True)), 200): t3_modules_group.items.add(*CatalogEntry.objects.filter( typeID__in=ids)) for ids in tools.sublists(list(charges.values_list('typeID', flat=True)), 200): charges_group.items.add(*CatalogEntry.objects.filter(typeID__in=ids)) for ids in tools.sublists( list(capital_ships.values_list('typeID', flat=True)), 200): capital_ships_group.items.add(*CatalogEntry.objects.filter( typeID__in=ids)) duration = time.time() - start logger.info('Initialized item groups (took %.2f sec.)', duration)