Unfinished town bot. It finds trash, flowers, and bugs within a 8 digit barton zip (ie. [1-9] 100 [4 digit code] 21009999).
It DOES collect all of the items, however I can't seem to find out how to successfully make it save to the inventory -- therefore the items aren't 'collected' officially.
I know that there are several GSI methods that Gaia uses and I can't find out if I am just doing it wrong, or if it needs to be set off in a specific order (bot protection maybe)?
Either way this is as is. Maybe someone will finish it. My notes are included.
HTTP Wrapper Class (very basic -- continuing project, Cookie Support).
PHP Code:
import urllib2
import urllib
import re
from cookielib import CookieJar
class HttpWrapper:
cookies = CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies))
def __init__(self):
self.opener.addheaders = [
('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13'),
('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
('Accept-Language', 'en-gb,en;q=0.5'),
('Accept-Encoding', 'gzip,deflate'),
('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'),
('Keep-Alive', '115'),
('Connection', 'keep-alive'),
('Cache-Control', 'max-age=0'),
('Referer', 'https://www.idcourts.us/repository/partySearch.do')]
def Request (self, act, url, post_data):
if act == False:
response = self.opener.open(url)
return response.read()
else:
edata = urllib.urlencode(post_data)
response = self.opener.open(url, edata)
return response.read()
def Get(self, URL):
return self.Request(False, URL, "")
def Post(self, URL, pdata):
return self.Request(True, URL, pdata)
def Clear(self):
self.cookies._cookies.clear()
def Between(self, sParse, start, finish):
x = re.compile(start + "([^>]+)" + finish)
i = x.findall(sParse)
return i
#how to import
# from HTTPWrapper import HttpWrapper
# wrapper = HttpWrapper()
# wrapper.Get("WHATEVER")
The actual bot it's self. It is in testing stages... It is ready to be automated if you can figure out how to get it to save. Just remove the comments.
Thanks to Arti for the Gaia Login!PHP Code:
from HTTPWrapper import HttpWrapper
import re
Wrapper = HttpWrapper()
def run():
#if (login(raw_input("Username: "), raw_input("Password: ")) == True):
if (login("Username", "Password") == True):
zip = "91002099" # Subject to change, testing purposes.
#zip = raw_input("Barton ZIP: ")
#Entry should be 4 digits, not 8.
crawl(zip, get_sid())
else:
print ("Invalid username / password...")
def get_sid():
return Wrapper.Between(Wrapper.Get("http://www.gaiaonline.com/chat/gsi/gateway.php?v=sushi&m=109%04"), "%05%01", "")[0]
def crawl(zip, sid):
print ("[ Searching ] " + zip)
####COLLECT BUGS###########
# bugs = {}
# bugs = create_list(
# Wrapper.Get("http://www.gaiaonline.com/chat/gsi/gateway.php?&v=sushi&m=360%01" + zip + "%01" + sid + "%04"))
# print "[ Bugs Found : " + str(bugs) + " ]"
########################################
######### EXTRA FOR TESTING ############
#seperate trash and flowers into different lists.
#trash = {}
#flowers = {}
#for i in range(0, (len(trashFlower))):
# if (len(trashFlower[i]) > 3):
# if trashFlower[i][0] == "t":
# trash[len(trash) + 1] = trashFlower[i]
# else:
# flowers[len(flowers) + 1] = trashFlower[i]
###########################################
###########################################
trashFlower = create_list(Wrapper.Get("http://www.gaiaonline.com/chat/gsi/gateway.php?&v=sushi&m=362%01" + zip + "%01" + sid + "%04"))
collect_tf(zip, trashFlower)
def collect_tf(zip, tempList):
for x in range(1, len(tempList)):
tof = "6" if str(tempList[x][0]) == 't' else "5"
#tof = trash or flower. trash = 6, flower = 5
vals = "363%01" + zip + "%01" + tof + "%01" + tempList[x] + "%04"
temp = Wrapper.Get("http://www.gaiaonline.com/chat/gsi/gateway.php?v=sushi&m=" + vals)
print tempList[x]
#The save function? I can't figure out the order.
#sid = get_sid()
#save = Wrapper.Get("http://www.gaiaonline.com/chat/gsi/gateway.php?v=sushi&m=374%01" + sid + "%04")
#save2 = Wrapper.Get("http://www.gaiaonline.com/chat/gsi/gateway.php?v=sushi&m=365%010%01" + sid + "%011%04")
#print save
#print save2
def create_list(list):
i = 0
d = {}
for pair in [val.split('%02') for val in list.split('%01')[1:-1]]:
d[i] = pair[0]
i = i + 1
return d
def login(username, password):
source = Wrapper.Get("http://www.gaiaonline.com/auth/login/")
inputPattern = re.compile("<input([^>]+)>")
inputs = inputPattern.findall(source)
fieldPattern = re.compile("([a-zA-Z0-9\-\_]+)\=\"([^\"]{0,})\"")
fieldList = {}
for y in range(0, len(inputs)):
fields = fieldPattern.findall(inputs[y])
name = ""
val = ""
for z in range(0, len(fields)):
if fields[z][0] == "name":
name = fields[z][1]
elif fields[z][0] == "value":
val = fields[z][1]
try:
fieldList[name] = val
except:
pass
fieldList["username"] = username
fieldList["password"] = password
login = Wrapper.Post("http://www.gaiaonline.com/auth/login/", fieldList)
return login.find("Log Out") != -1
run()
#Thanks to Arti of LogicalGamers.com for the Login.
My Gaia Towns GSI Recordings...
Code:http://www.gaiaonline.com/chat/gsi/gateway.php?&v=sushi&m= 113 %01 Gaia55_Sid %04 (TELLS YOU GOLD AMT) 360 61002097 Gaia55_Sid %04 (Tells you bugs) 362 61002097 Gaia55_Sid %04 (Tells you flowers and trash) Collect 363 61002097 5 trash/flower id (5 = FLOWERS, 6 = TRASH) 361 31002097 bug id (Collect Bug) All the values you need to collect are between %01 and %02 ------------- %04 = PACKET TERMINATOR %01 = PACKET DATA PARSER Barton room id break down id: 61002088 1 - 9 rooms. 100 - filler. 2088 zip code ----------- v=sushi&m=363 %01 81001099 %01 5 %01 f551579 %04 (FLOWER) Successful collect f: 363%01%05%012 successful collect t: 363%01%05%011 (TRASH AND BUG) failed: invalid+item 374 SSID (Possible save function but can't get to work?) I think that the save might have multiple gsi steps as an event to prevent potential bots. Must test this theory...
Results 1 to 2 of 2
Thread: Unfinished Town Bot - Python
- 14 May. 2015 06:00am #1
Unfinished Town Bot - Python
- 14 May. 2015 01:54pm #2
- Join Date
- Apr. 2013
- Location
- Minnesota
- Posts
- 1,325
- Reputation
- 114
- LCash
- 0.00
nice work, i'll be playing around with this when i have some time.
+1 for py