本文整理汇总了Python中db.Database.cursor方法的典型用法代码示例。如果您正苦于以下问题:Python Database.cursor方法的具体用法?Python Database.cursor怎么用?Python Database.cursor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.Database
的用法示例。
在下文中一共展示了Database.cursor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from db import Database [as 别名]
# 或者: from db.Database import cursor [as 别名]
class EmailService:
def __init__(self):
self.db = Database().get_connection()
def start(self):
while True:
print ">>> checking for new emails...."
self.iter()
print "<<< sleeping for %d seconds..." % CHECK_INTERVAL
time.sleep(CHECK_INTERVAL)
def iter(self):
cur = self.db.cursor()
cur.execute("SELECT email,email_password,last_email_id FROM users")
for res in cur:
email, password, id = res
EmailWorker(email=email, password=password, last_seq_id=id).run()
cur.close()
示例2: __init__
# 需要导入模块: from db import Database [as 别名]
# 或者: from db.Database import cursor [as 别名]
class AccountWorker:
def __init__(self, email=None, password=None, last_seq_id=0):
self.email = email
self.password = password
self.last_seq_id = last_seq_id
def update_messages(self):
""" This method runs in its own thread."""
try:
server = get_mail_server(self.email)
except UnknownEmailProvider:
print "unknown email provider:", self.email
return
self.db = Database().get_connection()
self.load_user_id()
self.conn = imaplib.IMAP4_SSL(server)
self.conn.login(self.email, self.password)
self.conn.select()
# TODO: more efficient fetching of messages
#criteria = "ALL AND SMALLER 32768"
criteria = "ALL"
typ, data = self.conn.search(None, criteria)
if typ != 'OK':
return
for num in data[0].split():
print " fetching:", num
typ, data = self.conn.fetch(num, '(RFC822)')
#print 'Message %s\n%s\n' % (num, data[0][1])
if typ != 'OK':
continue
try:
msg = data[0][1]
except IndexError:
continue
self.process_email(msg)
def process_email(self, data):
mp = MessageProcessor(data=data)
mp.parse_message()
info = mp.get_info()
print " info:", info
orders = info['orders']
for order_id in orders:
o = self.find_order(order_id)
if o:
self.update_order(order_id, orders[order_id])
else:
self.insert_order(order_id, orders[order_id])
def find_order(self, order_id):
# FIXME: currently using email_info field for order_id
cur = self.db.cursor()
cur.execute("SELECT info, vendor, price FROM orders WHERE email_info='%s'" % order_id)
for res in cur:
return dict(info=res[0], vendor=res[1], price=res[2])
def insert_order(self, order_id, order):
# FIXME: currently using email_info field for order_id
#self.db.execute("INSERT INTO orders (user_id, email_info, vendor, price) VALUES (%d, %s, %s, %f)", order['
pass
def update_order(self, order_id, order):
pass
def load_user_id(self):
cur = self.db.cursor()
cur.execute("SELECT id FROM users WHERE email=%s", self.email)
for id in cur:
self.user_id = id
cur.close()
break