コード例 #1
0
def load(login):
    compare = {'same': {}, 'diff': {}}
    for _, req in login.items():
        if "bytes" not in req:
            continue
        if req['method'] == 'GET' and 'headers' in req and (
                'cookie' in req['headers'] or 'Cookie' in req['headers']):
            try:
                if 'cookie' in req['headers']:
                    del req['headers']['cookie']
                else:
                    del req['headers']['Cookie']
                # s = requests.Session()
                # s.mount("https://" + urlparse(req['url']).netloc, HTTP20Adapter())
                # r = s.get(req['url'], headers=req['headers'], timeout=5)
                headers = common.strip_colon(req['headers'])
                r = requests.get(req['url'], headers=headers, timeout=10)
            except Exception as e:
                print(str(e))
                continue
            byte, text = common.find_length(r, True)
            is_similar, similarity = common.similar(
                byte, req['length'], text,
                extr_resource(host.replace('/', '_'), req['url']))
            if is_similar:
                compare['same'][req['url']] = [byte]
            else:
                compare['diff'][req['url']] = [byte, req['bytes'], similarity]
    f = open(
        os.path.join('headers', 'compare',
                     host.replace('/', '_') + '.json'), 'w+')
    f.write(json.dumps(compare))
コード例 #2
0
            try:
                l1 = np.mean(w1[left_context + right_context], axis=0)
                l2 = common.sigmoid(l1.dot(w2[target_samples].T))

                d2 = l2 - l2_target
                d1 = d2.dot(w2[target_samples])

                w1[left_context + right_context] -= d1 * alpha
                w2[target_samples] -= np.outer(d2, l1) * alpha
            except Exception as e:
                print("in nlpblankNN.py : ", l1.dot(w2[target_samples].T),
                      rev_i, target_i, e, target_samples)
                return (w1, w2)
            # finally :
            #     print (w2[target_samples].T, rev_i, target_i, target_samples)

            # if (rev_i == 0 and target_i == 3):
            #     print(l1.shape, l2.shape, w2[target_samples].shape, d1.shape, d2.shape)
            #     return
    return (w1, w2)


(nw1, nw2) = train2l(w1, w2)

#write the weights to file so that they can be reloaded
np.savetxt('nlpNNBlank_w1.txt', nw1, delimiter=",")
np.savetxt('nlpNNBlank_w2.txt', nw2, delimiter=",")

print(common.similar('king', nw1, nw2, word2index))
コード例 #3
0
def addItemToQuickbar(typeid):
    dontShow()
    itemname = api.getNameFromID(typeid)
    pyautogui.moveTo(200, 10)
    pyautogui.sleep(0.3)
    thing = pyautogui.locateOnScreen('imgs/regionalmarkettopleft.png',
                                     confidence=0.9)
    thing2 = pyautogui.locateOnScreen('imgs/search.png', confidence=0.9)
    if thing is None or thing2 is None:
        print("im blind")
        return addItemToQuickbar(typeid)
    search_market(itemname)
    cm.sleep(4)
    searchareacapturepos = cm.Area(thing.left, thing.top + 100,
                                   thing2.left - thing.left + 50, 400)

    for loopidx in range(20):
        ocr = cm.grabandocr(searchareacapturepos)
        ocrlines = ocr.splitlines()
        if loopidx == 10:
            search_market(itemname)
            cm.sleep(0.5)
        stringdict = {}
        curstring = ""
        for idx, s in enumerate(ocrlines):
            s = s.lower()
            if (len(s.split()) <= 11 or len(s.split()[-1]) < 2):
                if curstring:
                    stringdict[curstring.strip()] = idx - 1
                curstring = ""
            else:
                curstring += s.split()[-1] + " "
            if (idx == len(ocrlines) - 1):
                stringdict[curstring.strip()] = idx - 1
        highestsim = -1
        bestidx = 0
        for s in stringdict:
            cursim = cm.similar(itemname.lower(), s)
            if cursim > highestsim:
                highestsim = cursim
                bestidx = stringdict[s]
        if (highestsim > 0.8):
            s = ocrlines[bestidx]
            print("found item in search results: " + s)
            offsetpos = searchareacapturepos
            mousex = offsetpos.x + int(s.split()[6]) / 4 + 5
            mousey = offsetpos.y + int(s.split()[7]) / 4 + 5

            cm.clickxy(mousex, mousey)
            cm.sleep(1.5)

            thing = pyautogui.locateOnScreen('imgs/search.png', confidence=0.9)
            marketnamearea = cm.Area(thing.left + 158, thing.top + 14, 375, 30)
            ocr = cm.grabandocr(marketnamearea)
            marketname = ""
            for line in ocr.splitlines():
                if len(line.split()) > 11:
                    marketname += line.split()[-1] + ' '
            #strips marketname of whitespace and the list 4 characters, which should be: " i ©"
            marketname = marketname.strip()[:-4]
            print("read marketname while adding item: " + marketname)
            #marketname is the ocr result, itemname is the actual item were trying to add
            if (cm.similar(marketname.lower(), itemname.lower()) < 0.75):
                print("clicked wrong item while adding, retrying")
                return addItemToQuickbar(typeid)

            cm.clickxy(mousex, mousey, right=True)
            cm.sleep(0.2)
            cm.clickxy(mousex + 52, mousey + 29)
            print("old itemlist:")
            print(itemlist)
            if itemname not in itemlist:
                itemlist.append(itemname)
            itemlist.sort(key=str.lower)
            print("new itemlist:")
            print(itemlist)
            return

        if loopidx > 12:
            #we only get here if it didnt find an item: the item must have been in a collapsed category
            for s in ocr.splitlines():
                if (len(s.split()) > 11 and len(s.split()[-1]) > 3):
                    #we do NOT want to open the blueprint category
                    if not "prints" in s and not "react" in s:
                        offsetpos = searchareacapturepos
                        mousex = offsetpos.x + int(s.split()[6]) / 4 + 5
                        mousey = offsetpos.y + int(s.split()[7]) / 4 + 5
                        cm.clickxy(mousex, mousey)
                        break
        cm.sleep(0.5)

    print("looped through item adding a lot without success, aborting")
    sys.exit()
コード例 #4
0
def similar_nlpNN(target='horrible'):
    return common.similar(target, w1, w2, word2index)
コード例 #5
0
ファイル: orderstuff.py プロジェクト: Sceptix/evetradebot
def changeOrder(order, newprice):
    refreshOrderList()
    position, itemsinlist = getOrderPosition(order)
    itemname = api.getNameFromID(order.typeid)
    print("changing order of item: " + itemname + " in position: " +
          str(position))
    if order.bid:
        actingPoint, listheight = variables.bidaplh
    else:
        actingPoint, listheight = variables.sellaplh
    pyautogui.moveTo(actingPoint.x, actingPoint.y)
    cm.sleep(0.2)

    #this scrolls so the order is visible, and adjusts the position
    itemsfitinlist = math.ceil(listheight / 20)
    if (position >= itemsfitinlist):
        pagescrollcount = math.floor(position / itemsfitinlist)
        position -= (itemsinlist % itemsfitinlist)
        pyautogui.scroll(int(-130 * itemsfitinlist * pagescrollcount))
    pyautogui.move(0, 20 * position)
    pyautogui.click(button='right', clicks=1)
    cm.sleep(0.5)
    pyautogui.move(35, 10)
    cm.sleep(0.5)
    pyautogui.click()
    thing = pyautogui.locateOnScreen("imgs/modifyorder.png", confidence=0.9)
    for a in range(100):
        if thing is None:
            thing = pyautogui.locateOnScreen("imgs/modifyorder.png",
                                             confidence=0.9)
            cm.sleep(0.2)
        else:
            break
    if thing is None:
        refreshAllOrders()
        return changeOrder(order, newprice)
    box = cm.Area(thing.left + 100, thing.top + 21, 300, 19)
    ocr = cm.grabandocr(box).splitlines()
    ocrname = ""
    for line in ocr:
        if (len(line.split()) > 11):
            ocrname += line.split()[-1] + " "
    print("checking if we clicked the right order...")
    print("itemname: " + itemname.lower() + ", ocrname: " + ocrname)
    if cm.similar(ocrname.lower(), itemname.lower()) < 0.5:
        print("failed similar check")
        cm.clickxy(thing.left + 265, thing.top + 192)
        cm.sleep(0.5)
        refreshAllOrders()
        return changeOrder(order, newprice)
    cm.sleep(0.2)
    pyautogui.keyDown('ctrl')
    pyautogui.keyDown('c')
    cm.sleep(0.2)
    pyautogui.keyUp('c')
    pyautogui.keyUp('ctrl')
    realprice = pyperclip.paste()
    cm.safetypewrite(newprice)
    cm.sleep(0.2)
    pyautogui.typewrite(['enter'])
    cm.sleep(0.5)
    thing = pyautogui.locateOnScreen("imgs/warning.png", confidence=0.9)
    if thing is not None:
        cm.clickPointPNG("imgs/yesno.png", 20, 10)
    #reset scroll
    pyautogui.moveTo(actingPoint.x + 10, actingPoint.y + 10)
    pyautogui.scroll(100000)
    order.price = float(newprice)
    order.issuedate = cm.getEVETimestamp()
コード例 #6
0
ファイル: orderstuff.py プロジェクト: Sceptix/evetradebot
def cancelOrder(order):
    if (order is None or order.finished or not order.canChange()):
        print("Invalid cancel, ignoring")
        return
    refreshOrderList()
    refreshAllOrders()

    position, itemsinlist = getOrderPosition(order)
    print("cancelling buyorder: " + api.getNameFromID(order.typeid))

    if order.bid:
        actingPoint, listheight = variables.bidaplh
    else:
        actingPoint, listheight = variables.sellaplh
    pyautogui.moveTo(actingPoint.x, actingPoint.y)
    cm.sleep(0.2)
    #this scrolls so the order is visible, and adjusts the position
    itemsfitinlist = math.ceil(listheight / 20)
    if (position >= itemsfitinlist):
        pagescrollcount = math.floor(position / itemsfitinlist)
        position -= (itemsinlist % itemsfitinlist)
        pyautogui.scroll(int(-130 * itemsfitinlist * pagescrollcount))
    pyautogui.move(0, 20 * position)
    pyautogui.click(button='right', clicks=1)
    cm.sleep(0.2)
    #clicking market details on order and checking if we clicked the right order
    pyautogui.move(40, 68)
    pyautogui.click()
    cm.sleep(0.5)
    quickbar.dontShow()
    cm.sleep(0.2)
    thing = pyautogui.locateOnScreen('imgs/search.png', confidence=0.9)
    marketnamearea = cm.Area(thing.left + 158, thing.top + 14, 375, 30)
    ocr = cm.grabandocr(marketnamearea)
    marketname = ""
    for line in ocr.splitlines():
        if len(line.split()) > 11:
            marketname += line.split()[-1] + ' '
    marketname = marketname.strip()
    print("read marketname while cancelling order: " + marketname)
    if (cm.similar(marketname.lower(),
                   api.getNameFromID(order.typeid).lower()) < 0.5):
        print("clicked wrong order while cancelling, retrying")
        return cancelOrder(order)

    pyautogui.moveTo(actingPoint.x, actingPoint.y)
    cm.sleep(0.2)
    if (position >= itemsfitinlist):
        pagescrollcount = math.floor(position / itemsfitinlist)
        position -= (itemsinlist % itemsfitinlist)
        pyautogui.scroll(int(-130 * itemsfitinlist * pagescrollcount))
    pyautogui.move(0, 20 * position)
    pyautogui.click(button='right', clicks=1)
    cm.sleep(0.2)

    pyautogui.move(40, 115)
    pyautogui.click()
    for ih in variables.itemhandlerlist:
        if order.bid:
            if areOrdersTheSame(ih.buyorder, order):
                ih.buyorder = None
        else:
            for so in ih.sellorderlist:
                if areOrdersTheSame(so, order):
                    so = None
    print("successfully cancelled order")