def parse_notification(code, msg, notificationID): if code in NOTIFICATION_CODES and not msg is None: #try: if code == 10: # bill issued to corp or alliance r = NOTIFICATION_CODES[code][1] parameters = [m.groupdict() for m in r.finditer(msg)] if not len(parameters) == 1: return msg else: parameters = parameters[0] return '''A bill of {0:,} ISK, due {1} owed by you to {2} was issued {3}. This bill is for extending the lease on your office at {4}.'''.format( int(parameters['amount']), _format_datetime(_parse_windows_dates(parameters['dueDate'])), EveName.objects.get_name(parameters['creditorID']), _format_datetime(_parse_windows_dates(parameters['currentDate'])), get_location_name(parameters['externalID2']) ) #except: # log.warning('Could not decode notificationID {0}'.format(notificationID)) # pass return '{0}:\n{1}'.format( NOTIFICATION_CODES[code], msg ) else: return msg
def __unicode__(self): try: return u'{0} @ {1}'.format( self.typeName, get_location_name(self.locationID)) except: return u'{0} @ {1}'.format(self.typeName, self.locationID)
def get_top_level_locations(self, characterIDs, regionID=None): asset_locations = self.filter(owner__in=characterIDs) if regionID: asset_locations = asset_locations.filter(regionID=regionID) asset_locations = asset_locations.distinct('locationID'). \ values_list('locationID', flat=True) locations = [get_location(locationID) for locationID in asset_locations] out = [] for location in locations: if type(location) is long: locationID = location else: locationID = location.pk out.append({'regionName': get_location_regionName(location), 'regionID': get_location_regionID(location), 'solarSystemName': get_location_solarSystemName(location), 'solarSystemID': get_location_solarSystemID(location), 'name': get_location_name(locationID), 'locationID': locationID}) return out
def location(self): location = get_location_name(self.locationID) if location == self.locationID: try: location = ItemLocationName.objects.get(itemID=self.locationID) except ItemLocationName.DoesNotExist: return location return location
def update_all_markets(*args, **kwargs): market_updates = [] for market in Market.objects.filter( Q(cached_until__lte=datetime.now(tz=UTC)) | Q(cached_until=None)): market_updates.extend(update_market(market.locationID)) market.updated() log.info('Updating "{0}" market'.format(get_location_name(market.locationID))) chord(market_updates, write_static_prices.s()).apply_async()
def parse_rowset(rowset, locationID=None, parent=None, path=()): contents = [] for row in rowset: if hasattr(row, 'locationID'): locationID = row.locationID if locationID in location_cache: locationName = location_cache[locationID] else: locationName = get_location_name(locationID) location_cache[locationID] = locationName if row.typeID in type_cache: typeName = type_cache[row.typeID] else: try: item_type = InvType.objects.get(pk=row.typeID) typeName = item_type.typeName except InvType.DoesNotExist: typeName = None item = { 'itemID': row.itemID, 'locationID': locationID, 'locationName': locationName, 'typeID': row.typeID, 'typeName': typeName, 'quantity': row.quantity, 'flag': row.flag, 'singleton': row.singleton, 'parent': parent, } if hasattr(row, 'rawQuantity'): item['rawQuantity'] = row.rawQuantity asset = AssetClass() asset.from_item(item, path) asset.owner = owner if hasattr(asset, 'update_from_api'): asset.update_from_api(item, self) asset.save() if hasattr(row, 'contents'): item['contents'] = parse_rowset(row.contents, locationID=locationID, parent=row.itemID, path=path+(row.itemID,)) asset.compute_container_volume() asset.compute_container_value() asset.save() contents.append(item) return contents
def annotate_locations(self, asset_locations): for asset_location in asset_locations: locationID = asset_location['locationID'] location_key = self._location_data_key(locationID) location_data = self._cache_get(location_key) if not location_data: location = get_location(locationID) location_data = { 'regionName': get_location_regionName(location), 'regionID': get_location_regionID(location), 'solarSystemName': get_location_solarSystemName(location), 'solarSystemID': get_location_solarSystemID(location), 'name': get_location_name(locationID) } self._cache_data(location_key, location_data) asset_location.update(location_data)
def get(self, request, locationID): market = get_object_or_404(Market, locationID=locationID) key = hash(('prices_list', locationID)) content = cache.get(key, None) if not content: prices = MarketItem.objects.filter(locationID=locationID).order_by('typeName') response = render(request, self.template_name, dictionary={ 'cached_until': market.cached_until, 'name': get_location_name(market.locationID), 'prices': prices, }) cacheTimeSeconds = (market.cached_until - datetime.now(tz=UTC)).total_seconds() cache.set(key, response.content, timeout=cacheTimeSeconds) return response else: return HttpResponse(content=content)
def get(self, request, locationID): market = get_object_or_404(Market, locationID=locationID) key = hash(('prices_list', locationID)) content = cache.get(key, None) if not content: prices = MarketItem.objects.filter( locationID=locationID).order_by('typeName') response = render(request, self.template_name, dictionary={ 'cached_until': market.cached_until, 'name': get_location_name(market.locationID), 'prices': prices, }) cacheTimeSeconds = (market.cached_until - datetime.now(tz=UTC)).total_seconds() cache.set(key, response.content, timeout=cacheTimeSeconds) return response else: return HttpResponse(content=content)
def parse_notification(code, msg, notificationID): if code in NOTIFICATION_CODES and not msg is None: #try: if code == 10: # bill issued to corp or alliance r = NOTIFICATION_CODES[code][1] parameters = [m.groupdict() for m in r.finditer(msg)] if not len(parameters) == 1: return msg else: parameters = parameters[0] return '''A bill of {0:,} ISK, due {1} owed by you to {2} was issued {3}. This bill is for extending the lease on your office at {4}.'''.format( int(parameters['amount']), _format_datetime(_parse_windows_dates(parameters['dueDate'])), EveName.objects.get_name(parameters['creditorID']), _format_datetime( _parse_windows_dates(parameters['currentDate'])), get_location_name(parameters['externalID2'])) #except: # log.warning('Could not decode notificationID {0}'.format(notificationID)) # pass return '{0}:\n{1}'.format(NOTIFICATION_CODES[code], msg) else: return msg
def location(self): return get_location_name(self.locationID)
def parse_rowset(rowset, locationID=None, parent=None, path=()): contents = [] for row in rowset: if hasattr(row, 'locationID'): locationID = row.locationID if locationID in location_cache: locationName = location_cache[locationID] else: locationName = get_location_name(locationID) location_cache[locationID] = locationName group = None category = None typeName = None if row.typeID in type_cache and row.typeID in group_cache and row.typeID in category_cache: typeName = type_cache[row.typeID] group = group_cache[row.typeID] category = category_cache[row.typeID] else: try: item_type = InvType.objects.get(pk=row.typeID) typeName = item_type.typeName group = item_type.group.pk category = item_type.group.category.pk type_cache[row.typeID] = typeName group_cache[row.typeID] = group category_cache[row.typeID] = category except: pass item = { 'locationID': locationID, 'locationName': locationName, 'typeID': row.typeID, 'typeName': typeName, 'quantity': row.quantity, 'flag': row.flag, 'groupID': group, 'categoryID': category, 'singleton': row.singleton, 'parent_id': parent, } if hasattr(row, 'rawQuantity'): item['rawQuantity'] = row.rawQuantity asset, created = AssetClass.objects.update_or_create( owner=owner, itemID=row.itemID, defaults=item) if asset_with_name(asset): itemIDs_to_names.append(str(asset.itemID)) if hasattr(row, 'contents'): item['contents'] = parse_rowset(row.contents, locationID=locationID, parent=row.itemID, path=path + (row.itemID, )) item["itemID"] = asset.itemID asset.update_from_api(item, self) asset.compute_container_volume() asset.compute_container_value() asset.save(update_fields=[ 'regionID', 'solarSystemID', 'item_value', 'item_volume', 'container_volume', 'container_value' ]) contents.append(item) return contents
def __unicode__(self): try: return u'{0} @ {1}'.format(self.typeName, get_location_name(self.locationID)) except: return u'{0} @ {1}'.format(self.typeName, self.locationID)
def __unicode__(self): return get_location_name(self.locationID)
def homeStation(self): return get_location_name(self.homeStationID)
def parse_rowset(rowset, locationID=None, parent=None, path=()): contents = [] for row in rowset: if hasattr(row, 'locationID'): locationID = row.locationID if locationID in location_cache: locationName = location_cache[locationID] else: locationName = get_location_name(locationID) location_cache[locationID] = locationName group = None category = None typeName = None if row.typeID in type_cache and row.typeID in group_cache and row.typeID in category_cache: typeName = type_cache[row.typeID] group = group_cache[row.typeID] category = category_cache[row.typeID] else: try: item_type = InvType.objects.get(pk=row.typeID) typeName = item_type.typeName group = item_type.group.pk category = item_type.group.category.pk type_cache[row.typeID] = typeName group_cache[row.typeID] = group category_cache[row.typeID] = category except: pass item = { 'locationID': locationID, 'locationName': locationName, 'typeID': row.typeID, 'typeName': typeName, 'quantity': row.quantity, 'flag': row.flag, 'groupID': group, 'categoryID': category, 'singleton': row.singleton, 'parent_id': parent, } if hasattr(row, 'rawQuantity'): item['rawQuantity'] = row.rawQuantity asset, created = AssetClass.objects.update_or_create(owner=owner, itemID=row.itemID, defaults=item) if asset_with_name(asset): itemIDs_to_names.append(str(asset.itemID)) if hasattr(row, 'contents'): item['contents'] = parse_rowset(row.contents, locationID=locationID, parent=row.itemID, path=path + (row.itemID,)) item["itemID"] = asset.itemID asset.update_from_api(item, self) asset.compute_container_volume() asset.compute_container_value() asset.save(update_fields=['regionID', 'solarSystemID', 'item_value', 'item_volume', 'container_volume', 'container_value']) contents.append(item) return contents