本文整理汇总了Python中importer.Importer.do_import方法的典型用法代码示例。如果您正苦于以下问题:Python Importer.do_import方法的具体用法?Python Importer.do_import怎么用?Python Importer.do_import使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类importer.Importer
的用法示例。
在下文中一共展示了Importer.do_import方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ImportDatabase
# 需要导入模块: from importer import Importer [as 别名]
# 或者: from importer.Importer import do_import [as 别名]
def ImportDatabase(self):
"""Import an old-style .db qwitter database, or .session file into the current session's storage."""
def import_buffer (tablename, buffername):
table = new.load_table(tablename)
newtable = new.convert_table(table)
buf = self.session.get_buffer_by_name(buffername)
buf.storage.extend(newtable)
buf.storage.sort(key=lambda a: calendar.timegm(rfc822.parsedate(a['created_at'])))
buf.storage = misc.RemoveDuplicates(buf.storage, lambda x: x['id'])
f = wx.Frame(None, wx.ID_ANY, "FileDialog")
dlg = wx.FileDialog(f, message="Select Database", defaultDir=paths.data_path(), wildcard="Session files (*.session)|*.session|Qwitter Databases (*.DB)|*.db")
f.Raise()
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetPath()
dlg.Destroy()
f.Destroy()
else:
output.speak(_("Canceled"), True)
dlg.Destroy()
f.Destroy()
return
if filename.lower().endswith('.db'):
new = Importer(filename)
home = new.load_table("tweets")
directs = new.load_table("directs")
mentions = new.load_table("replies")
sent = new.load_table("sent")
total = len(home) + len(directs) + len(mentions) + len(sent)
yesno = wx.MessageBox(_("Are you sure you want to import %d items from old database?") % total, _("Are you sure?"), style=wx.YES|wx.NO)
if yesno == wx.YES:
output.speak(_("Importing, please wait."), True)
else:
return output.speak(_("Canceled."), True)
for i in [("tweets", "Home"), ("replies", "Mentions"), ("directs", "Direct Messages"), ("sent", "Sent")]:
import_buffer(*i)
elif filename.lower().endswith('.session'):
try:
new = SessionImporter(filename)
except TypeError:
return output.speak(_("Session type mismatch."))
new.do_import()
wx.MessageBox(_("Import completed successfully."), _("Import complete."))