當前位置: 首頁>>代碼示例>>Python>>正文


Python Importer.do_import方法代碼示例

本文整理匯總了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."))
開發者ID:Piciok,項目名稱:TheQube,代碼行數:45,代碼來源:interface.py


注:本文中的importer.Importer.do_import方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。