コード例 #1
0
def chkRec(itemID, count):
    # recursive function that adds the ingredients list of the recipe that produces the current item to that item's
    # ingredients dict

    # get the recipe object by searching the master recipe list for the given item id
    recObjs = gw2lib.findByX(itemID, 'output_item_id', masterRecipeList)
    # if there's exactly 1 resulting recipe:
    if len(recObjs) == 1:
        recObj = recObjs[0]
        # deepcopy the ingredients list (oh python, you crazy reference obsessed fool)
        recChk = deepcopy( recObj['ingredients'] )
        # go through each ingredient:
        for ingr in recChk:
            # set the buy price to 2 (will change later to actually get the buy price)
            ingr['costInfo'] = None
            # update the count- multiply the count of the ingredient by the count of the recipe 'above' it
            # this ensures nested recipes have the correct total counts for the ingredients at the bottom
            ingr['count'] *= count
            # add the id to the ids list, which for now just tracks every item id involved in the top level recipe
            ingrID = ingr['item_id']
            if masterItemList[str(ingrID)]['TPable']:
                tradeIDs.append(ingrID)
            else:
                allIDsDict[ingrID] = {'source':'something', 'cost':'someNumber'}
            # add the item name
            ingr['name'] = masterItemList[str(ingr['item_id'])]['name'] #gw2lib.findByID(ingr['item_id'], masterItemList)['name']
            # get the ingredients list (if it exists) for the recipe 'below'
            ingr['ingredients'] = chkRec(ingrID, ingr['count'])
        # return the updated ingredients list
        return recChk
    # if there are no recipes that produce itemID, return None
    elif len(recObjs) < 1:
        return None
    # if there are multiple recipes that produce an item, output a message about it; I'll figure out what to do about
    # it later
    else:
        print ">1 recipes found"
        return None
コード例 #2
0
    else:
        rsNames = sys.argv[1:]

# if rsNames is empty, read in all rune/sigil names from file
if len(rsNames) < 1:
    with open(gw2lib.searchFolderName+'allRuneSigilNames.txt') as nameFile:
        rsNames = [x[:-1] for x in nameFile]

# grab all the rune and sigil objects from file
with open(gw2lib.searchFolderName+gw2lib.runeAndSigilsFilename) as rsRefFile:
        runeSigilObjs = json.load(rsRefFile)

# for each rune/sigil name:
for rsName in rsNames:
    # get the object by name
    rsID0 = gw2lib.findByX(rsName, 'name', runeSigilObjs)
    ''' NOTE: here, may need to fix, or replace getID() function '''
    # if more than 1 object is returned, that's wrong, exit (this should probly be handled better)
    if len(rsID0) > 1:
        sys.exit()

    # get the id number
    rsID = rsID0[0]['id']

    # using the id, get the containers list for that rune/sigil from its file id#.json
    with open(gw2lib.searchFolderName+str(rsID)+'.json', 'r') as ctList:
        containersList = json.load(ctList)

    pricesList = []
    idsCsvList = []
    start = 0