Commits

gao shuai committed cdf104a

S6_db_creater

Comments (0)

Files changed (1)

s60/kcbS60_dbcreater.py

+#coding=utf-8
+
+import urllib
+import e32dbm
+
+import json
+
+class kcbTermDb:
+	def __init__(self,tname,startday=None,kcbs=None):
+		self.path="e:\\"+tname
+		self.tname=tname
+		self.startday=startday
+		self.kcbs=kcbs
+		self.db = e32dbm.open(self.path, 'c')
+		if kcbs!=None:
+			self.save()
+	def save(self):
+ 		self.db['startday']=self.startday
+		self.db['tname']=self.tname
+		self.ctr=0
+		print 'saving......'
+		for kcb in self.kcbs:
+			self.db[str(self.ctr)]=str(kcb)
+			self.ctr+=1
+		print 'done'
+
+	def printall(self):
+		for k, v in self.db.iteritems():
+			print k, '\t', json.read(v)
+
+
+def loadJson(location='http://kb.gongda.tk/api/gao/nowterm.json'):
+	DATA = urllib.urlopen(location).read()
+	JSON = json.read(DATA)
+	return JSON
+#
+def saveDb(JSON,dbName):
+	TERM=kcbTermDb(dbName,JSON['startday'],JSON['kcbs'])
+	return TERM
+
+
+#j=loadJson()
+print 5
+#s=saveDb(j,"20110429")
+print 5
+#readDb(s.path)
+t=kcbTermDb('20110429')
+#t.printall()
+#def handleData(JSON):
+#c['week'].replace('L','')
+week=9l
+day='6'
+time='1'
+for i in t.db.items():
+    try:
+        dic=eval(i[1])
+        if week in eval(dic['week']) and dic['day']==day and dic['time']==time:
+            for k in dic.keys():
+                print k,dic[k]
+    except TypeError:
+        print i