Esempio n. 1
0
def couldNotFindItem(context, **kwargs):
	if "session" not in kwargs:
		return
		
	session = kwargs["session"]
	item = None
	
	r = ClosetContentsRequest(session)
	r.skipParseResponse = True
	r.doRequest()
	
	if "descId" in kwargs:
		descId = kwargs["descId"]
		pattern = re.compile("<option value='([0-9]+)' descid='%s'>([^<>]*) \([0-9]+\)<\/option>" % descId)
		match = pattern.search(r.responseText)
		if match:
			item = {"id":int(match.group(1)), "descId":descId, "name":match.group(2)}
		else:
			raise ItemNotFoundError("Could not find item associated with description ID '%s'." % descId)
			
	elif "itemId" in kwargs:
		itemId = kwargs["itemId"]
		pattern = re.compile("<option value='%s' descid='([0-9]+)'>([^<>]*) \([0-9]+\)<\/option>" % itemId)
		match = pattern.search(r.responseText)
		if match:
			item = {"id":itemId, "descId":int(match.group(1)), "name":match.group(2)}
		else:
			raise ItemNotFoundError("Could not find item associated with ID '%s'." % itemId)
			
	elif "itemName" in kwargs:
		itemName = kwargs["itemName"]
		pattern = re.compile("<option value='([0-9]+)' descid='([0-9]+)'>%s \([0-9]+\)<\/option>" % itemName)
		match = pattern.search(r.responseText)
		if match:
			item = {"id":int(match.group(1)), "descId":int(match.group(2)), "name":itemName}
		else:
			raise ItemNotFoundError("Could not find item with name '%s'." % itemName)
	
	if item != None:
		r = ItemDescriptionRequest(session, item["descId"])
		itemInfo = r.doRequest()
		for k,v in itemInfo.iteritems():
			item[k] = v
		
		Report.trace("itemdatabase", "Discovered new item: %s" % item)
		
		context["item"] = item
		FilterManager.executeFiltersForEvent("discoveredNewItem", session=session, item=item)
Esempio n. 2
0
def getItemFromName(itemName, session=None):
    "Returns information about an item given its name."
    if not __isInitialized:
        init()

    try:
        return __itemsByName[itemName].copy()
    except KeyError:
        cxt = FilterManager.executeFiltersForEvent("couldNotFindItem",
                                                   session=session,
                                                   itemName=itemName)
        if "item" in cxt:
            item = cxt["item"]
            addItem(item)
            return item.copy()
        raise ItemNotFoundError("The item '%s' is unknown." % itemName)
Esempio n. 3
0
def getItemFromId(itemId, session=None):
    "Returns information about an item given its ID."
    if not __isInitialized:
        init()

    try:
        return __itemsById[itemId].copy()
    except KeyError:
        cxt = FilterManager.executeFiltersForEvent("couldNotFindItem",
                                                   session=session,
                                                   itemId=itemId)
        if "item" in cxt:
            item = cxt["item"]
            addItem(item)
            return item.copy()
        raise ItemNotFoundError("Item ID %s is unknown." % itemId)