Example #1
0
def get_items(eft_text):
	name = None
	ship = None
	items_list = []
	fit_lines = eft_text.split('\n')

	for line in fit_lines:
		line = line.strip()

		# Skip newlines
		if line == '':
			continue

		# Not going to bother with equals, as I don't know all of the edge cases yet.
		if '=' in line:
			continue

		# Skip empty slots
		if 'empty' in line:
			continue

		# If it's a title line.
		if line[0] == '[':
			line = line.strip('[]')
			ship, name = line.split(',')
			ship = ship.strip()
			name = name.strip()
			items_list.append(ship)
		elif ',' in line:
			module, charge = line.split(',')
			items_list.append(module)
			# We're not going to worry about the charges for now.
		else:
			items_list.append(line)

	item_quantities = dict(Counter(items_list))
	items = list()
	for item, quantity in item_quantities.iteritems():
		item_dict = {
			'name': item,
			'quantity': quantity,
		    'typeid': None
		}

		# Populate typeID
		db_item = getItem(item)
		if db_item:
			item_dict['typeid'] = db_item.typeID

		items.append(item_dict)
	return {
		'ship': ship,
		'name': name,
		'items': items
	}
Example #2
0
	def getPrices(cls, typeIDs=None, region=None, system='Jita'):
		basequeryurl = EveCentral.URL
		if typeIDs is None:
			typeIDs = EveCentral.validids
		toRequest = set(typeIDs)
		requested = set()
		priceMap = {}

		if region:
			basequeryurl += 'regionlimit=%s&' % getRegion(region).ID

		if system:
			basequeryurl += 'usesystem=%s&' % getSystem(system).ID

		# Eliminate all items that don't have a market group as Eve Central doesn't track those items.
		culledRequest = []
		for typeID in toRequest:
			if typeID in EveCentral.validids:
				culledRequest.append(typeID)
		toRequest = set(culledRequest)

		# Hit the cache for some fish and see if we can get any yummmm.
		# Disable the cache for now.
		"""
		for id in toRequest:
			price = EveCentral.cache.get(id)
			if price:
				priceMap[price.id] = price
				requested.add(id)
		toRequest = toRequest.difference(requested)
		"""

		while len(toRequest):
			requrl = basequeryurl
			for typeID in toRequest:
				newurl = requrl
				newurl += 'typeid=%d&' % typeID

				if len(newurl) < 2048:
					requrl = newurl
					requested.add(typeID)
				else:
					break

			requrl = requrl[:-1]
			#print len(requrl), requrl
			toRequest = toRequest.difference(requested)

			# Finally request the stuff we need
			htmlReply = urllib2.urlopen(requrl).read()
			rootnode = None
			try:
				rootnode = ET.fromstring(htmlReply)[0]
			except:
				print htmlReply
				return

			for typenode in rootnode:
				buyNode = typenode.find('buy')
				sellNode = typenode.find('sell')
				allNode = typenode.find('all')

				price = Price()
				price.id = int(typenode.attrib['id'])
				price.name = getItem(price.id).name
				price.buy.fromNode(buyNode)
				price.sell.fromNode(sellNode)
				price.all.fromNode(allNode)

				priceMap[price.id] = price
				EveCentral.cache.set(price.id, price)

		return priceMap