本文整理汇总了Python中PyDbLite.Base类的典型用法代码示例。如果您正苦于以下问题:Python Base类的具体用法?Python Base怎么用?Python Base使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Base类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: host
def host():
# show the user profile for that stock
db = Base('overall.db')
db.open()
#stocks = [r for r in db if r['state']==1]
stocks = [r for r in db]
return render_template('all.html', stocks=stocks)
示例2: KopeteLog
class KopeteLog():
def __init__(self, directory=None):
if not directory:
directory=os.path.join(os.path.expanduser("~"),
".kde/share/apps/kopete/logs")
self.messages = Base('kopete.db') # Database stuff - Initializing...
self.messages.create('protocol', 'date', 'time', 'msgfrom', 'msgto', 'sender', 'inbound', 'nick', 'message', mode='override')
for file in self.searchLogs(directory):
self.feedDatabase(file)
def searchLogs(self, dir):
logfiles = []
for (basepath, dirnames, filenames) in os.walk(dir):
for child in filenames:
if child.endswith (".xml"):
logfiles.append(os.path.join(basepath, child))
return logfiles
def feedDatabase(self, filepath):
if 'WlmProtocol' in filepath:
protocol = 'wlm'
elif 'ICQProtocol' in filepath:
protocol = 'icq'
elif 'JabberProtocol' in filepath:
protocol = 'jabber'
else:
protocol = 'unknown'
xmllog = parse(filepath)
for head in xmllog.getiterator('head'):
for date in head.getiterator('date'):
month=date.attrib['month']
year=date.attrib['year']
for contact in head.getiterator('contact'):
if contact.attrib.has_key('type'):
if contact.attrib['type'] == 'myself':
contactfrom = contact.attrib['contactId']
else:
contactto = contact.attrib['contactId']
for msg in xmllog.getiterator('msg'):
nick = msg.attrib['nick']
time = msg.attrib['time']
inbound = msg.attrib['in']
message = msg.text
sender = msg.attrib['from']
date = datetime.strptime("%s;%s;%s" %
(year, month, msg.attrib['time']) ,
"%Y;%m;%d %H:%M:%S")
self.messages.insert(
protocol=protocol,
date=date.strftime("%Y%m%d"),
time=date.strftime("%H:%M:%S"),
msgfrom=contactfrom, msgto=contactto,
sender=sender, inbound=inbound, nick=nick,
message=message)
示例3: sell
def sell():
# show the user profile for that stock
sm = StockManager()
stock = Stock_Profile('2002')
current = stock.get_result(0)[0]
db = Base('overall.db')
db.open()
stocks = [r for r in db if r['sell']==1 and (r['date']==current)]
return render_template('buy.html', stocks=stocks)
示例4: users
def users():
db = Base('alf.db')
db.open()
users = []
for r in db:
n = r['name']
p = r['pwd']
users.append((n, p))
return render_template('user.html', users=users)
示例5: alf
def alf():
db = Base('alf.db')
db.open()
user = request.form['Username']
pwd = request.form['password']
user_verf = [r['password'] for r in db if r['name'] == user]
if len(user_verf) > 0:
if user_verf[0] == pwd:
return 'Hello, ' + user
else:
return 'Who are you!!!'
示例6: __init__
class alf123:
def __init__(self, sID, onePiece):
today = datetime.date.today()
self.sID = sID
self.opp = onePiece
self.historyDB = Base("F://alfStock//"+"alf123"+'.history')
self.currentDB = Base("F://alfStock//"+"alf123"+'.current')
self.historyDB.open()
self.currentDB.open()
db = Base("F://alfStock//"+str(today)+'.db')
impactDB = Base("F://alfStock//"+str(today)+'.yv')
if db.exists():
db.open()
recs = [ r for r in db if r['sid'] == self.sID ]
if len(recs) > 0:
self.history = recs[0]['history']
self.sCurrent = recs[0]['current']
else:
print "already existed: ", len(db)
self.insertHistory(db)
else:
db.create('sid','history', 'current')
self.insertHistory(db)
if impactDB.exists():
self.idb = impactDB
else:
impactDB.create('sid','UpOrDown')# U:up; D:down
impactDB.open()
impactDB.commit()
self.idb = impactDB
def insertHistory(self, db):
db.open()
self.history = self.stockHistoryGet()
self.sCurrent = self.stockCurrent()
db.insert(sid = self.sID, history = self.history, current = self.sCurrent)
db.commit()
def TTLUrlOpen(self, url, rc):
retryCount = rc
if retryCount > 2:
pass
else:
try:
response = urllib2.urlopen(url, None, 2.5)
except URLError, e:
print "url"
except socket.timeout:
print "Timed out!"
response = TTLUrlOpen(self, url, retryCount+1)
示例7: Queue
class Queue(object):
""" Simple queue with PyDbLite backend. """
def __init__(self, queue_type=0, config=None):
if config is not None:
# copy config
pass
else:
self.commit = False
self.db_filename = "/tmp/queue.pydb"
self.mode = "override"
self.queue = Base(self.db_filename)
def create_queue(self):
self.queue.create('id', 'item', mode = self.mode)
self.queue.create_index('id')
return None
def push(self, item):
self.queue.insert(self.length(), item)
return None
def pop(self):
if not self.is_empty():
id = self.length() - 1
r = self.queue._id[id]
self.queue.delete(r)
return r
else:
return None
def list(self):
return self.queue.records
def length(self):
return len(self.queue)
def is_empty(self):
return self.length() == 0
def commit(self):
if self.commit is True:
self.queue.commit()
return None
示例8: reset
def reset(self):
if not self.tags:
self.tags = Base(DB_FILE_TAGS)
self.tags.create('realpath', 'category', 'tag', mode = 'override')
self.tags.create_index('realpath')
self.tags.create_index('category')
Organizer.reset(self)
示例9: initDB
def initDB(self):
self.db = Base("maindb")
self.db.create("id", "data", mode="open")
self.searchdb = Base("searchdb")
self.searchdb.create("module", "id", "timestamp", "data", mode="open")
self.cache = tools.storage()
try:
if len(self.db) < 3:
self.default()
except:
self.default()
records = self.db(id="version")
if records[0]["data"] < self.db_version:
self.default()
示例10: welcome
def welcome():
db = Base('alf.db')
db.create('name','pwd',mode="open") #override
user = request.form['Username']
passwd = request.form['password1']
db.insert(name=user,pwd=passwd)
db.commit()
return 'welcome ' + user
示例11: __init__
def __init__(self):
self.EventPassport = Base('EventPassport/EventPassport.pdl')
#check if the DB exists. If Yes, open, if not
#create it:
if not self.EventPassport.exists():
self.genPDL()
else:
self.EventPassport.open()
self.CleanEvents = CleanEvents.CleanData()
示例12: __init__
def __init__(self, queue_type=0, config=None):
if config is not None:
# copy config
pass
else:
self.commit = False
self.db_filename = "/tmp/queue.pydb"
self.mode = "override"
self.queue = Base(self.db_filename)
示例13: __init__
class ArticleDB:
"""class for persistent storage of articles.
what is stored from each Article object is defined in Article.TO_SAVE
"""
def __init__(self, dbfile, mode = 'open', autocommit = False):
self.db = Base(dbfile)
self.db.create(*Article.TO_SAVE, **{'mode': mode})
self.db.create_index(*INDEX_ON)
self.autocommit = autocommit
def insertArticle(self, art):
"""insert article into database, with id consistency check"""
present = []
if art.id_int != None:
present.extend(self.db._id_int[art.id_int])
# if art.idZBL != None:
# present.extend(self.db._idZBL[art.idZBL])
# if art.idMR != None:
# present.extend(self.db._idMR[art.idMR])
ids = list(set([rec['__id__'] for rec in present])) # unique ids
present = [self.db[id] for id in ids] # remove duplicate identical entries (coming from matches on more than one id on the same article)
new = art
for old in present: # FIXME HACK turns off consistency checking
try:
new.mergeWith(Article.Article(record = old)) # article already present in database -- check if ids are consistent, update it with new info from art
except Exception, e:
# logging.error('inconsistent database contents (%i overlapping records); leaving database unchanged' % (len(present)))
#logging.info('inconsistency between \n%s\n%s' % (new, Article.Article(old)))
logging.warning('inconsistency between %s and %s' % (new, Article.Article(old)))
# return False
if len(present) == 0:
# logging.debug('inserting a new article')
pass
else:
# logging.debug('replacing %i old (consistent) record(s) for %s' % (len(present), new))
pass
self.db.delete(present)
id = self.db.insert(**new.__dict__)
if self.autocommit:
self.commit()
return True
示例14: __init__
def __init__(self, directory=None):
if not directory:
directory=os.path.join(os.path.expanduser("~"),
".kde/share/apps/kopete/logs")
self.messages = Base('kopete.db') # Database stuff - Initializing...
self.messages.create('protocol', 'date', 'time', 'msgfrom', 'msgto', 'sender', 'inbound', 'nick', 'message', mode='override')
for file in self.searchLogs(directory):
self.feedDatabase(file)
示例15: getStock
def getStock(self, sid):
sname = self.dbname(sid)
exist = os.path.isfile(sname)
db = ''
if (exist):
#read db
db = Base(sname)
db.open()
else:
#create a new db
db = Base(sname)
db.create('date','buySig','sellSig', 'state', 'buy', 'sell' ,mode="override")
db.open()
return db