# HG changeset patch # User "Rex Tsai " # Date 1225794829 -28800 # Node ID 4a051d1784568d89871b43e2ac2bd271c836a4a8 # Parent 1b7805535040c5d602184eb08971f192cb5b3bc3# Parent 5fa938cbe058462b46da32a8712bfe1c99f6a2e7 mreged. diff -r 1b7805535040 -r 4a051d178456 pyikb/Parser.py --- a/pyikb/Parser.py Tue Nov 04 18:30:56 2008 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -import re,string -from sgmllib import SGMLParser - -class ContentParser(SGMLParser): - def __init__(self): - SGMLParser.__init__(self) - self.anchor = {'link':'', 'title':''} - self.anchorlist = [] - self.liattr={} - self.inside_elements=['site'] - self.pat=re.compile('\r|\t|\n') - - def start_a(self, attributes): - """For each anchor tag, pay attention to the href and title attributes.""" - href, title = '', '' - for name, value in attributes: - if name.lower() == 'href': href = value - if name.lower() == 'title': title = value - self.anchor['link'] = href - self.anchor['title'] = title - self.inside_elements.append('anchor') - - def end_a(self): - self.anchorlist.append(self.anchor) # store the anchor in a list - self.anchor = {'link':'', 'title':''} # reset the dictionary, - self.inside_elements.pop() - - def handle_data(self, text): - if self.inside_elements[-1]=='anchor': - self.anchor['title'] = text - if self.inside_elements[-1]=='li': - text=self.pat.sub(' ',text) - text=string.split(text," ") - if self.liattcl in self.liattr: - self.liattr[self.liattcl]=self.liattr[self.liattcl]+text - else: - self.liattr[self.liattcl]=text - - def start_li(self,attributes): - self.liattcl='' - attrs = dict(attributes) - if attrs.has_key('class'): - self.liattcl=attrs['class'] - self.inside_elements.append('li') - - def end_li(self): - if self.inside_elements[-1]=='li': - self.inside_elements.pop() - diff -r 1b7805535040 -r 4a051d178456 pyikb/ikariam.py --- a/pyikb/ikariam.py Tue Nov 04 18:30:56 2008 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,85 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -import os,sys,re,string -import cookielib,urllib2,urllib # for urlencode -import time -from lconf import LoadConfigfile -from Parser import ContentParser - -class connection(object): - def __init__(self): - self.page='' - self.confdata=LoadConfigfile().cd - self.baseurl='http://'+self.confdata['server'] - self.COOKIEFILE = '/tmp/ikcookies.lwp' - self.cj = cookielib.LWPCookieJar() - if os.path.isfile(self.COOKIEFILE): - self.cj.load(self.COOKIEFILE) - opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj)) - opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.8.1.12pre) Gecko/20071220 BonEcho/2.0.0.12pre')] - urllib2.install_opener(opener) - - def login(self): - if not os.path.isfile(self.COOKIEFILE): - print "create cookie file"+self.COOKIEFILE - params = {"universe":self.confdata['server'], \ - "name":self.confdata['user'], \ - "password":self.confdata['pass']} - - data = urllib.urlencode(params) - self.page=urllib2.urlopen(self.baseurl+'/index.php?action=loginAvatar&function=login',data).read() - self.cj.save(self.COOKIEFILE) - return 1 - - def parser(self): - parser=ContentParser() - parser.feed(self.page) - parser.close - for x in parser.liattr.keys(): - print x,parser.liattr[x] - #parser.anchorlist: - - def logout(self): - logout=urllib2.urlopen(self.baseurl+'/index.php?action=loginAvatar&function=logout').read() - os.remove(self.COOKIEFILE) - return 1 - - def plunder(self): - '/index.php?view=plunder&destinationCityId=1978' - - - def upgradetest(self): - urllib2.urlopen(self.baseurl+'/index.php?view=academy&id=117257&position=9').read() - params = {"action":'CityScreen', \ - "function":'upgradeBuilding', \ - "id":'117257',\ - "position":'9',\ - "level":'7',\ - "oldView":'academy'} - print urllib2.urlopen(self.baseurl+'/index.php?view=townHall&id=117257&position=0#upgrade',urllib.urlencode(params)).read() - return 1 - -def help(): - print ("Usage: %s [Option] [Channel] [second]") % os.path.basename(sys.argv[0]) - print ("Option: ") - helplist=[ - ("-h","--help","show this usage message."), - ("-g","--game","Login to the game") - ] - helplist.sort() - for x in helplist: - print ("\t%2s, %-25s %s" % x) - -if __name__=='__main__': - if len(sys.argv) == 1: - help() - sys.exit(2) # common exit code for syntax error - else: - arglist=sys.argv[1:] - if arglist[0] in ('--game','-g'): - gc=connection() - gc.login() - gc.parser() - gc.logout() - - diff -r 1b7805535040 -r 4a051d178456 pyikb/lconf.py --- a/pyikb/lconf.py Tue Nov 04 18:30:56 2008 +0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -import os,string -class LoadConfigfile(object): - def __init__(self): - profile = os.environ["HOME"]+'/.eagleeye.pm' - self.cd={} - if os.path.isfile(profile): - print "Loading Config file." - cfile=open(profile,'r') - for line in cfile.xreadlines(): - if line[0:3]=='$::': - con=string.split(line[3:-2]) - self.cd[con[0]]=con[2][1:-1] - else: - print "File don't exist." - diff -r 1b7805535040 -r 4a051d178456 pyikriam/createAccount.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pyikriam/createAccount.py Tue Nov 04 18:33:49 2008 +0800 @@ -0,0 +1,47 @@ +import urllib2,urllib + +from ikariam import fake_moz +from lazy.www import c + +class CreateAccount: + """ + For create sheep to cheat. take care of the ip address & email check by yourself. + """ + def __init__(self,account,email,password,server): + self.account=account + self.password=password + self.server=server + self.email=email + headers=[('Referer','http://'+self.server[self.server.find('.')+1:]+'/register.php')] + self.browser = fake_moz(headers) + urllib2.install_opener(self.browser) + pass + + def ca(self): + self.baseurl='http://'+self.server + params = { + "function":"createAvatar",\ + "name":self.account,\ + "email":self.email,\ + "password":self.password,\ + "agb":"on"} + self.ret=c(self.baseurl+'/index.php?action=newPlayer').get(params).get_content() + pass + +class confirme: + def __init__(self,confirmeurl): + self.confirmeurl=confirmeurl + self.browser = fake_moz() + urllib2.install_opener(self.browser) + pass + + def run(self): + self.ret=c(self.confirmeurl).get().get_content() + pass + +""" +ikariamca=CreateAccount('someac','kevin@butyshop.com','contest123','s2.ikariam.tw') +a=ikariamca.ca() +confirme("http://s2.ikariam.tw/index.php?action=newPlayer&function=validateEmail&hash=c239c92a94690066078ca95c993d348b&id=70997").run() +""" + diff -r 1b7805535040 -r 4a051d178456 pyikriam/ikariam.py --- a/pyikriam/ikariam.py Tue Nov 04 18:30:56 2008 +0800 +++ b/pyikriam/ikariam.py Tue Nov 04 18:33:49 2008 +0800 @@ -11,34 +11,34 @@ class fake_moz(object): __metaclass__ = decorator - def __init__(self): + def __init__(self,headers=0): + fakeheaders=[('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.8.1.12pre) Gecko/20071220 BonEcho/2.0.0.12pre')] + if headers: + fakeheaders=fakeheaders+headers super(fake_moz, self).__init__() cookie_jar = cookielib.LWPCookieJar() cookie_proc = urllib2.HTTPCookieProcessor(cookie_jar) opener = urllib2.build_opener(cookie_proc) - opener.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-TW; rv:1.8.1.12pre) Gecko/20071220 BonEcho/2.0.0.12pre')] + opener.addheaders = fakeheaders fake_moz.set_backend(self, opener) self.cookie_jar = cookie_jar pass pass - class Ikariam: cities = {} COOKIEFILE = '/tmp/ikariam.lwp' def __init__(self): - browser = fake_moz() - self.browser = browser - self._cookie_jar = browser.cookie_jar + self.browser = fake_moz() + self._cookie_jar = self.browser.cookie_jar if os.path.isfile(self.COOKIEFILE): self._cookie_jar.load(self.COOKIEFILE) pass - urllib2.install_opener(browser) - + urllib2.install_opener(self.browser) self.confdata=LoadConfigfile().cd self.baseurl='http://'+self.confdata['server']