示例#1
0
def export_chats(chats, path, format, db, messages=None, skip=True, progress=None):
    """
    Exports the specified chats from the database under path.

    @param   chats     list of chat dicts, as returned from SkypeDatabase
    @param   path      full path of directory where to save
    @param   format    export format (html|txt|xlsx|csv|filename.ext).
                       If format is filename.ext, a single file is created:
                       for single chat exports and multi chat XLSX exports
                       (for multi-file exports, filenames are named by chats).
    @param   db        SkypeDatabase instance
    @param   messages  list messages to export if a single chat
    @param   skip      whether to skip chats with no messages
    @param   progress  function called before exporting each chat, with the
                       number of messages exported so far
    @return            (list of exported filenames, number of chats exported)
    """
    files, count = [], 0
    def make_filename(chat):
        if len(format) > 4: # Filename already given in format
            filename = os.path.join(path, format)
        else:
            args = collections.defaultdict(str); args.update(chat)
            filename = "%s.%s" % (conf.ExportChatTemplate % args, format)
            filename = os.path.join(path, util.safe_filename(filename))
            filename = util.unique_path(filename)
        return filename
    main.logstatus("Exporting %s from %s %sto %s.",
                   util.plural("chat", chats), db.filename,
                   "" if len(format) > 4 else "as %s " % format.upper(),
                   format if len(format) > 4 else path)

    if format.lower().endswith(".xlsx"):
        filename = make_filename(chats[0])
        count = export_chats_xlsx(chats, filename, db, messages, skip, progress)
        files.append(filename)
    else:
        if not os.path.exists(path):
            os.makedirs(path)
        export_func = (export_chats_xlsx if format.lower().endswith("xlsx")
                       else export_chat_csv if format.lower().endswith("csv")
                       else export_chat_template)
        message_count = 0
        for chat in chats:
            if skip and not messages and not chat["message_count"]:
                main.log("Skipping exporting %s: no messages.",
                         chat["title_long_lc"])
                if progress: progress(message_count)
                continue # continue for chat in chats
            main.status("Exporting %s.", chat["title_long_lc"])
            if progress: progress(message_count)
            filename = make_filename(chat)
            msgs = messages or db.get_messages(chat)
            chatarg = [chat] if "xlsx" == format.lower() else chat
            export_func(chatarg, filename, db, msgs)
            message_count += chat["message_count"]
            files.append(filename)
        count = len(files)
    return (files, count)
示例#2
0
def export_chats_xlsx(chats,
                      filename,
                      db,
                      messages=None,
                      skip=True,
                      progress=None):
    """
    Exports the chats to a single XLSX file with chats on separate worksheets.

    @param   chats     list of chat data dicts, as returned from SkypeDatabase
    @param   filename  full path and filename of resulting file
    @param   db        SkypeDatabase instance
    @param   messages  list of messages to export if a single chat
    @param   skip      whether to skip chats with no messages
    @param   progress  function called before exporting each chat, with the
                       number of messages exported so far
    @return            number of chats exported
    """
    count, style = 0, {0: "timestamp", 2: "wrap", 3: "hidden"}

    writer = xlsx_writer(filename, autowrap=[2])
    message_count = 0
    for chat in chats:
        if skip and not messages and not chat["message_count"]:
            main.log("Skipping exporting %s: no messages.",
                     chat["title_long_lc"])
            continue  # continue for chat in chats
        main.status("Exporting %s.", chat["title_long_lc"])
        if progress: progress(message_count)
        parser = skypedata.MessageParser(db, chat=chat, stats=False)
        writer.add_sheet(chat["title"])
        writer.set_header(True)
        writer.writerow(["Time", "Author", "Message", "Skype Name"],
                        {3: "boldhidden"})
        writer.set_header(False)
        msgs = messages or db.get_messages(chat)
        for m in msgs:
            text = parser.parse(m, output={"format": "text"})
            try:
                text = text.decode("utf-8")
            except UnicodeError:
                pass
            values = [m["datetime"], m["from_dispname"], text, m["author"]]
            style[1] = "local" if db.id == m["author"] else "remote"
            writer.writerow(values, style)
        message_count += chat["message_count"]
        count += 1
    writer.close()
    return count
示例#3
0
 def _SendReport(self, report_kwargs):
     """Tries to send report in the background, shows result message."""
     try_count = 0
     while try_count < 3 and not send_report(**report_kwargs):
         try_count += 1
     if try_count < 3:
         self.edit_text.Value = ""
         self.edit_text.SetFocus()
         self.SetScreenshot(None)
         text, style = "Feedback sent, thank you!", wx.OK
     else:        
         text = "Could not post feedback. Connection problems?"
         style = wx.OK | wx.ICON_WARNING
     main.status("")
     wx.CallLater(500, wx.MessageBox, text, self.Title, style)
示例#4
0
def export_chats_xlsx(chats, filename, db, messages=None, skip=True, progress=None):
    """
    Exports the chats to a single XLSX file with chats on separate worksheets.

    @param   chats     list of chat data dicts, as returned from SkypeDatabase
    @param   filename  full path and filename of resulting file
    @param   db        SkypeDatabase instance
    @param   messages  list of messages to export if a single chat
    @param   skip      whether to skip chats with no messages
    @param   progress  function called before exporting each chat, with the
                       number of messages exported so far
    @return            number of chats exported
    """
    count, style = 0, {0: "timestamp", 2: "wrap", 3: "hidden"}

    writer = xlsx_writer(filename, autowrap=[2])
    message_count = 0
    for chat in chats:
        if skip and not messages and not chat["message_count"]:
            main.log("Skipping exporting %s: no messages.",
                     chat["title_long_lc"])
            continue # continue for chat in chats
        main.status("Exporting %s.", chat["title_long_lc"])
        if progress: progress(message_count)
        parser = skypedata.MessageParser(db, chat=chat, stats=False)
        writer.add_sheet(chat["title"])
        writer.set_header(True)
        writer.writerow(["Time", "Author", "Message", "Skype Name"],
                        {3: "boldhidden"})
        writer.set_header(False)
        msgs = messages or db.get_messages(chat)
        for m in msgs:
            text = parser.parse(m, output={"format": "text"})
            try:
                text = text.decode("utf-8")
            except UnicodeError: pass
            values = [m["datetime"], m["from_dispname"], text, m["author"]]
            style[1] = "local" if db.id == m["author"] else "remote"
            writer.writerow(values, style)
        message_count += chat["message_count"]
        count += 1
    writer.close()
    return count
示例#5
0
 def OnSend(self, event):
     """
     Handler for clicking to send feedback, hides the dialog and posts data
     to feedback web service.
     """
     text = self.edit_text.Value.strip()
     text_short = text[:500] + ".." if len(text) > 500 else text
     bmp = self.cb_bmp.Value and self.screenshot
     if text:
         ok = wx.MessageBox("Send the entered text%s?\n\n\"%s\"" % (
                            " and screenshot" if bmp else "", text_short),
                            self.Title, wx.OK | wx.CANCEL | 
                            wx.ICON_INFORMATION)
         text = (text if wx.OK == ok else "")
     if text:
         self.Hide()
         kwargs = {"type": "feedback", "content": text}
         if bmp: kwargs["screenshot"] = util.wx_bitmap_to_raw(bmp)
         main.status("Submitting feedback..")
         wx.CallAfter(self._SendReport, kwargs)
def test_no19():
    z=5
    assert status()==main()
def test_no18():
    z=2
    assert status()==record()
def test_no17():
    z=1
    assert status()==adminroom()
def test_no15():
    go=0
    assert record()==status()
示例#10
0
def test_no14():
    go=3
    assert record()==status()
示例#11
0
def test_no10():
    password="******"
    passwd=password
    assert Admin()==status()
示例#12
0
def test_no20():
    z=5
    assert status()==record()
示例#13
0
def export_chats(chats,
                 path,
                 format,
                 db,
                 messages=None,
                 skip=True,
                 progress=None):
    """
    Exports the specified chats from the database under path.

    @param   chats     list of chat dicts, as returned from SkypeDatabase
    @param   path      full path of directory where to save
    @param   format    export format (html|txt|xlsx|csv|filename.ext).
                       If format is filename.ext, a single file is created:
                       for single chat exports and multi chat XLSX exports
                       (for multi-file exports, filenames are named by chats).
    @param   db        SkypeDatabase instance
    @param   messages  list messages to export if a single chat
    @param   skip      whether to skip chats with no messages
    @param   progress  function called before exporting each chat, with the
                       number of messages exported so far
    @return            (list of exported filenames, number of chats exported)
    """
    files, count = [], 0

    def make_filename(chat):
        if len(format) > 4:  # Filename already given in format
            filename = os.path.join(path, format)
        else:
            args = collections.defaultdict(str)
            args.update(chat)
            filename = "%s.%s" % (conf.ExportChatTemplate % args, format)
            filename = os.path.join(path, util.safe_filename(filename))
            filename = util.unique_path(filename)
        return filename

    main.logstatus("Exporting %s from %s %sto %s.", util.plural("chat", chats),
                   db.filename,
                   "" if len(format) > 4 else "as %s " % format.upper(),
                   format if len(format) > 4 else path)

    if format.lower().endswith(".xlsx"):
        filename = make_filename(chats[0])
        count = export_chats_xlsx(chats, filename, db, messages, skip,
                                  progress)
        files.append(filename)
    else:
        if not os.path.exists(path):
            os.makedirs(path)
        export_func = (export_chats_xlsx if format.lower().endswith("xlsx")
                       else export_chat_csv if format.lower().endswith("csv")
                       else export_chat_template)
        message_count = 0
        for chat in chats:
            if skip and not messages and not chat["message_count"]:
                main.log("Skipping exporting %s: no messages.",
                         chat["title_long_lc"])
                if progress: progress(message_count)
                continue  # continue for chat in chats
            main.status("Exporting %s.", chat["title_long_lc"])
            if progress: progress(message_count)
            filename = make_filename(chat)
            msgs = messages or db.get_messages(chat)
            chatarg = [chat] if "xlsx" == format.lower() else chat
            export_func(chatarg, filename, db, msgs)
            message_count += chat["message_count"]
            files.append(filename)
        count = len(files)
    return (files, count)
示例#14
0
		chat_id = 1

		class FromUser:
			first_name = ""
			last_name = ""
			id = 1
		from_user = FromUser()
		text = ""
	message = Message()

def send_message_mock(
	chat_id, text, parse_mode=None,
	disable_web_page_preview=None, disable_notification=False,
	reply_to_message_id=None, reply_markup=None, timeout=None, **kwargs):
		print("RETURNED MESSAGE: " + text)
main.bot.send_message = send_message_mock

print("The app is started in debug mode.")
update = UpdateMock()
main.start(main.bot, update)

update.message.from_user.first_name = "hola"
update.message.from_user.last_name = "macchina"
update.message.text = "/auto 3"
main.macchina(main.bot, update)

update.message.text = "/postoguest tizio"
main.postoguest(main.bot, update)

main.status(main.bot, update)