changeset 64:19d2a7b175b3

Load configure data from .eagleeye.pm
author kevin@localhost.localdomain
date Wed, 22 Oct 2008 05:57:19 +0800
parents 1c42ae140ad3
children 4ba1e981716d
files pyikriam/__init__.py pyikriam/example.py pyikriam/lconf.py
diffstat 3 files changed, 27 insertions(+), 15 deletions(-) [+]
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
--- a/pyikriam/example.py	Wed Oct 22 05:40:57 2008 +0800
+++ b/pyikriam/example.py	Wed Oct 22 05:57:19 2008 +0800
@@ -1,6 +1,6 @@
 from __init__ import Ikariam
 
-i = Ikariam(server='s1.ikariam.tw', username='hychen', password='')
+i = Ikariam()
 city = i.city(117261)
 city.sync()
 print 'gold is'+city.gold
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pyikriam/lconf.py	Wed Oct 22 05:57:19 2008 +0800
@@ -0,0 +1,15 @@
+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."
+