diff pyikriam/__init__.py @ 64:19d2a7b175b3

Load configure data from .eagleeye.pm
author kevin@localhost.localdomain
date Wed, 22 Oct 2008 05:57:19 +0800
parents a4c364888197
children 7551342718b6
line wrap: on
line diff
--- a/pyikriam/__init__.py	Wed Oct 22 05:40:57 2008 +0800
+++ b/pyikriam/__init__.py	Wed Oct 22 05:57:19 2008 +0800
@@ -1,4 +1,5 @@
 from lazy.www import c
+from lconf import LoadConfigfile
 import cookielib
 import os
 import urllib2
@@ -7,11 +8,10 @@
 
     cities = {}
 
-    def __init__(self, server, username, password):
+    def __init__(self):
         self.COOKIEFILE = '/tmp/ikariam.lwp'
-        self.server=server
-        self.baseurl='http://'+self.server
-
+	self.confdata=LoadConfigfile().cd
+        self.baseurl='http://'+self.confdata['server']
         self.cj = cookielib.LWPCookieJar()
         if os.path.isfile(self.COOKIEFILE):
             self.cj.load(self.COOKIEFILE)
@@ -20,16 +20,18 @@
         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)
 
-        self.login(username, password)
+        self.login()
 
-    def login(self,username,password):     
-	print "login to %s...." % self.server
-        params = {"universe":self.server, "name":username, "password":password}
+    def login(self):     
+	print "login to %s...." % self.confdata['server']
+        params = {"universe":self.confdata['server'], \
+        "name":self.confdata['user'], \
+        "password":self.confdata['pass']}
         ret = c(self.baseurl+'/index.php?action=loginAvatar&function=login').get(params).get_content()
         self.cj.save(self.COOKIEFILE)
         
     def logout(self):
-	print "logut from %s...." % self.server
+	print "logut from %s...." % self.confdata['server']
         c(self.baseurl+'/index.php?action=loginAvatar&function=logout')
         os.remove(self.COOKIEFILE)
         
@@ -50,8 +52,3 @@
         xpath_gold = xpath_globalinfo + "/li[2]/a/span[@id='value_gold']/text()"
         self.gold = c(self.core.baseurl).get(self.params).find(xpath_gold).get_content()[0]
         
-if __name__ == '__main__':
-    i = Ikariam('hychen','pwdyouknow')
-    city = i.city(117261)
-    city.sync()
-    print city.gold