PDA

View Full Version : Python - Searching SDB for specific item.



|2eap
01-24-2017, 01:49 AM
So i've been tinkering around for awhile with some code and I can't seem to figure it out.

I've tried this




item = "Lost Desert Paint Brush"
if logged_in:
encodedItem = item.lower().replace(" ", "+").strip()
url = "[Only registered and activated users can see links]"
postdata = {}
postdata['obj_name'] = item
postdata['category'] = 0
html = acc.post(url, postdata)
print html
if 'Not finding any' in html:
print 'not in SDB'
else:
pos1 = html.find('<td align="left"><b>' + item + '<br>')
pos2 = html.find("back_to_inv[", pos1)
pos3 = html.find("]", pos2) + 1
postdata = {}
postdata['obj_name'] = item
if pin is not None:
postdata['pin'] = pin
postdata['offset'] = 0
postdata['category'] = 0
postdata[html[pos2:pos3]] = 1
html = acc.post("[Only registered and activated users can see links]", postdata)
if html.find("provides every Neopian") != -1:
print " Removed " + item + " x 1"
else:
print "error removing item"




And i've tried as a get





item = "Lost Desert Paint Brush"
if logged_in:
encodedItem = item.lower().replace(" ", "+").strip()
url = "[Only registered and activated users can see links]" + encodedItem + "&category=0"

html = acc.get(url)
print html
if 'Not finding any' in html:
print 'not in SDB'
else:
pos1 = html.find('<td align="left"><b>' + item + '<br>')
pos2 = html.find("back_to_inv[", pos1)
pos3 = html.find("]", pos2) + 1
postdata = {}
postdata['obj_name'] = item
if pin is not None:
postdata['pin'] = pin
postdata['offset'] = 0
postdata['category'] = 0
postdata[html[pos2:pos3]] = 1
html = acc.post("[Only registered and activated users can see links]", postdata)
if html.find("provides every Neopian") != -1:
print " Removed " + item + " x 1"
else:
print "error removing item"




I am successfully authorized on Neopets and logged in. It keep returning "Not finding any items matching your criteria" When it is in-fact in the SDB.

Furthermore, I've tried c/p the url exactly when doing a get and i still get "Not finding any items matching your criteria".

I've tested another users code using a different login method and mechanizing the browser and it seems to work following the paths/controllers.

What am I missing?

What is weird is, if I remove the check and just run the code straight through, it will remove the item IF it is in the SDB. if it is not in the SDB. it will still attempt to and say it has successfully done so even when it hasn't. The only time it prints error removing item is if there is a faulty pin.

Thanks lads, contact me here or skype(preferably) if you got me.

Vegeta
01-26-2017, 08:20 AM
Tum de dum

Zachafer
01-26-2017, 01:31 PM
@|2eap ([Only registered and activated users can see links])
You set the encodedItem variable but is not used in the rest of the code.
Debug the values of pos1, pos2, pos3, html[pos2:pos3], and html (after the final acc.post call) , and the problem should become obvious

Not sure what class you are using for web connections, but I know that some home-made solutions have problems with POSTing when a ? is in the URL.

|2eap
01-27-2017, 08:15 AM
@|2eap ([Only registered and activated users can see links])
You set the encodedItem variable but is not used in the rest of the code.
Debug the values of pos1, pos2, pos3, html[pos2:pos3], and html (after the final acc.post call) , and the problem should become obvious

Not sure what class you are using for web connections, but I know that some home-made solutions have problems with POSTing when a ? is in the URL.
The variable encodedItem in the first code snippet was just there from trying as a get in example two. I should have taken it out or commented it out :P but it's not needed in the post request.


And the second post request still removes the item from SDB. its the initial request for searching the specific item that returns the item is not in SDB. I've tried it as a get and post but it returns the same thing.

This is where it's happening.

url = "[Only registered and activated users can see links]"
postdata = {}
postdata['obj_name'] = item
postdata['category'] = 0
html = acc.post(url, postdata)
print html

or

encodedItem = item.lower().replace(" ", "+").strip()
url = "[Only registered and activated users can see links]" + encodedItem + "&category=0"

html = acc.get(url)
print html

I'm logging in with a edited working variation of neoaccount.py. But basically the same build

Daviid
01-27-2017, 03:52 PM
From my kad feeder:


def removeFromSDB(item):
#Search Item
html = acc.get("[Only registered and activated users can see links]" % urllib.quote_plus(item),"[Only registered and activated users can see links]")

#Check if the item was found on the SDB
if 'Not finding any items' in html:
return False

regex = '<td align="left"><b>%s<br><span class="medText">[\s\S]+?<td align="left"><b>([\w\s]+?)<\/b>[\s\S]+?back_to_inv\[(\d+?)\][\s\S]+?total_count=\'(\d+?)\'' % re.escape(item)

try:
category,code,amount = re.findall(regex,html)[0]
postData = ([
("back_to_inv["+code+"]",amount),
("pin",PIN), #Delete this if needed
("obj_name",urllib.quote_plus(item)),
("category","0"),
("offset","0")
])
html = acc.post("[Only registered and activated users can see links]",postData,"[Only registered and activated users can see links]" % urllib.quote_plus(item))
return True
except IndexError:
#Only items that contain the item we wanted ("Mau Codestone" => "Mau Codestone Plushie")
return False

|2eap I can send you my SDB remover if you want. I think I updated it not long ago but forgot to upload here.

Edit:
The code it's copied&pasted from another program and I just noticed that if you want to remove the item "Mau Codestone" and you have 10 it'll remove all of them. :P