本文整理汇总了Python中db.Database.remove方法的典型用法代码示例。如果您正苦于以下问题:Python Database.remove方法的具体用法?Python Database.remove怎么用?Python Database.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类db.Database
的用法示例。
在下文中一共展示了Database.remove方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sync
# 需要导入模块: from db import Database [as 别名]
# 或者: from db.Database import remove [as 别名]
def sync(user, password, since=None, localdb=None):
db = Database(localdb)
api = Simplenote(user, password)
dbg("LOCAL TO REMOTE:")
synced_count = 0
for note in db.values():
if note["CHANGED"]:
if not note.has_key("key") or note["key"].startswith(KEY_PREFIX):
dbg("NEW NOTE")
else:
dbg("CHANGED: %s" % note["key"])
if note["key"].startswith(KEY_PREFIX):
k = note["key"]
del note["key"]
else:
k = None
note = api.update(note)
note["CHANGED"] = False
db.update(note)
if k is not None:
db.remove(k)
synced_count += 1
if since:
rindex = api.index(since=since)
dbg(">>>> SINCE: %s" % since)
else:
rindex = api.index()
dbg("REMOTE TO LOCAL:")
dbg(">>>> RINDEX LEN: %s" % len(rindex))
for ritem in rindex:
key = ritem["key"]
if key not in db.keys(deleted=True):
dbg(" NEW: %s" % (key))
db.update(api.get(key))
synced_count += 1
litem = db.get(key)
if ritem["syncnum"] > litem["syncnum"]:
dbg(" UPD: %s" % (key))
db.update(api.get(key))
synced_count += 1
dbg("CLEAN UP:")
if since is None:
rkeys = api.keys().keys()
for k in db.keys(deleted=True):
if k not in rkeys:
dbg(" DEL: %s" % k)
db.remove(k)
synced_count += 1
else:
for k in db.keys(deleted=True):
litem = db.get(k)
if litem["deleted"] != 0:
dbg(" DEL: %s" % k)
db.remove(k)
sys.stderr.write("Synced %s notes.\n" % synced_count)
return time.time()
示例2: __init__
# 需要导入模块: from db import Database [as 别名]
# 或者: from db.Database import remove [as 别名]
class AutoMessageManager:
def __init__(self):
self.targets = Database()
self.recently_sent = False
def subscribe(self, bot, update):
if self.targets.add(str(update.message.chat_id)):
bot.sendMessage(chat_id=update.message.chat_id,
text=responses.subscribe)
else:
bot.sendMessage(chat_id=update.message.chat_id,
text=responses.already_subscribed)
def unsubscribe(self, bot, update):
if self.targets.remove(str(update.message.chat_id)):
bot.sendMessage(chat_id=update.message.chat_id,
text=responses.unsubscribe)
else:
bot.sendMessage(chat_id=update.message.chat_id,
text=responses.not_subscribed)
def job(self, bot):
try:
if self.recently_sent:
self.recently_sent = False
return
if valid_time():
print('preparando para executar o job')
menu = responses.cardapio()
self.recently_sent = True
for chat_id in self.targets:
try:
send_menu(bot, chat_id, menu)
except telegram.error.Unauthorized:
self.targets.remove(chat_id)
bot.sendMessage(
chat_id=config.MAINTAINER_ID,
text='Unauthorized: removed {}'.format(chat_id))
except telegram.error.ChatMigrated as e:
self.targets.remove(chat_id)
self.targets.add(str(e.new_chat_id))
bot.sendMessage(
chat_id=config.MAINTAINER_ID,
text='ChatMigrated: {} to {}'.format(
chat_id, e.new_chat_id))
except Exception as e:
error(bot, None, e)
print('job finalizado')
except Exception as e:
error(bot, None, e)