comparison pyikriam/ikariam.py @ 218:785c89e5db32

Remove those file, and change the addheader from fake moz
author kevin@localhost.localdomain
date Tue, 04 Nov 2008 16:01:25 +0800
parents 9f248c8460ce
children 7107c26ba197
comparison
equal deleted inserted replaced
215:4aad04928f66 218:785c89e5db32
9 from StringIO import StringIO 9 from StringIO import StringIO
10 10
11 class fake_moz(object): 11 class fake_moz(object):
12 __metaclass__ = decorator 12 __metaclass__ = decorator
13 13
14 def __init__(self): 14 def __init__(self,headers=0):
15 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')]
16 if headers:
17 fakeheaders=fakeheaders+headers
15 super(fake_moz, self).__init__() 18 super(fake_moz, self).__init__()
16 cookie_jar = cookielib.LWPCookieJar() 19 cookie_jar = cookielib.LWPCookieJar()
17 cookie_proc = urllib2.HTTPCookieProcessor(cookie_jar) 20 cookie_proc = urllib2.HTTPCookieProcessor(cookie_jar)
18 opener = urllib2.build_opener(cookie_proc) 21 opener = urllib2.build_opener(cookie_proc)
19 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')] 22 opener.addheaders = fakeheaders
20 fake_moz.set_backend(self, opener) 23 fake_moz.set_backend(self, opener)
21 self.cookie_jar = cookie_jar 24 self.cookie_jar = cookie_jar
22 pass 25 pass
23 pass 26 pass
24 27
27 30
28 cities = {} 31 cities = {}
29 COOKIEFILE = '/tmp/ikariam.lwp' 32 COOKIEFILE = '/tmp/ikariam.lwp'
30 33
31 def __init__(self): 34 def __init__(self):
32 browser = fake_moz() 35 self.browser = fake_moz()
33 self.browser = browser 36 self._cookie_jar = self.browser.cookie_jar
34 self._cookie_jar = browser.cookie_jar
35 37
36 if os.path.isfile(self.COOKIEFILE): 38 if os.path.isfile(self.COOKIEFILE):
37 self._cookie_jar.load(self.COOKIEFILE) 39 self._cookie_jar.load(self.COOKIEFILE)
38 pass 40 pass
39 41
40 urllib2.install_opener(browser) 42 urllib2.install_opener(self.browser)
41
42 self.confdata=LoadConfigfile().cd 43 self.confdata=LoadConfigfile().cd
43 self.baseurl='http://'+self.confdata['server'] 44 self.baseurl='http://'+self.confdata['server']
44 45
45 self.login() 46 self.login()
46 pass 47 pass