Quantcast

Jump to content


dogma22

Member Since 29 Dec 2015
Offline Private

Posts I've Made

In Topic: [Help] Calling all Greasemonkey experts. Is this possible?

25 January 2016 - 11:51 PM

Thank you Neoquest. You really helped out with this one :)

And thanks Juvian, I'll be sure to check your chrome extension.


In Topic: [Help] Calling all Greasemonkey experts. Is this possible?

25 January 2016 - 12:59 PM

*cracks knuckles*
 

import re
import sys
import urllib
import urllib2
import cookielib
 
cookie_jar = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie_jar))
 
 
def safeOpen(obj):
    try:
        src = opener.open(obj).read()
        if "http://images.neopets.com/neoboards/avatars/rubbish.gif" in src:
            sys.exit("Got the rubbish avatar")
        return src
    except Exception:
        print("HTTP request failed, trying again")
        return safeOpen(obj)
 
 
def buyBrush():
    store_src = safeOpen("http://www.neopets.com/generalstore.phtml")
    ref_ck = store_src.split(''''_ref_ck' value="''')[1].split('"')[0]
    req = urllib2.Request("http://www.neopets.com/generalstore.phtml", "buy_oii=91&store_type=&_ref_ck=%s&buy_oii_click.x=44&buy_oii_click.y=5&buy_oii_click=91" % ref_ck)
    safeOpen(req)
 
 
def discardInvent():
    stock_src = safeOpen("http://www.neopets.com/quickstock.phtml")
    item_ids = re.findall('id_arr\[\d+\]" value="\d+">', stock_src)
    data = {"buyitem": 0}
    for index, item in enumerate(item_ids):
        key, val = item_ids[index].replace('value="', "").replace(">", "").replace("'", "").replace('"', "").split(" ")
        data[key] = val
        data[key.replace("id_arr", "radio_arr")] = "discard"
    data["checkall"] = "on"
    data = urllib.urlencode(data)
    req = urllib2.Request("http://www.neopets.com/process_quickstock.phtml", data)
    safeOpen(req)
 
un = raw_input("Username: ")
pw = raw_input("Password: ")
opener.open('http://www.neopets.com/login.phtml', 'username=%s&password=%s' % (un, pw))
 
while 1:
    print("Buying 50 brushes...")
    for x in xrange(50):
        buyBrush()
    print("Discarding invent...")
    discardInvent()
 

I know it's not greasemonkey, but Python's better anyway, right? Download Python 2.7 and run that script with it, it'll buy and discard brushes until it gets the avatar.

Disclaimer: This script will discard your entire inventory, no matter the contents, so start with an empty invent.

 

 

Thank you for replying Neoquest. Python didn't come to my mind. This is great!

One small doubt, if I change

data[key.replace("id_arr", "radio_arr")] = "discard"

to

data[key.replace("id_arr", "radio_arr")] = "deposit"

it will deposit all of them in SDB and repeat buying?

What should I do, say if I want an alert when there are 4k brushes in my SDB?

 

Really appreciate your help. Thank you :)