Example #1
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()
         time.sleep(0.1)
         kwargs = {"type": "feedback"}
         kwargs["content"] = text
         if bmp:
             kwargs["screenshot"] = util.bitmap_to_raw(bmp)
         wx.CallAfter(lambda: send_report(**kwargs))
         wx.MessageBox("Feedback sent, thank you!", self.Title, wx.OK)
         self.edit_text.Value = ""
         self.edit_text.SetFocus()
         self.SetScreenshot(None)
Example #2
0
def export_chat_template(chat, filename, db, messages):
    """
    Exports the chat messages to file using templates.

    @param   chat      chat data dict, as returned from SkypeDatabase
    @param   filename  full path and filename of resulting file, file extension
                       .html|.txt determines file format
    @param   db        SkypeDatabase instance
    @param   messages  list of message data dicts
    """
    tmpfile, tmpname = None, None # Temporary file for exported messages
    try:
        is_html = filename.lower().endswith(".html")
        parser = skypedata.MessageParser(db, chat=chat, stats=is_html)
        namespace = {"db": db, "chat": chat, "messages": messages,
                     "parser": parser}

        if is_html:
            # Collect chat and participant images.
            namespace.update({"chat_picture": None, "chat_picture_raw": None,
                              "participants": [], })
            if chat["meta_picture"]:
                raw = skypedata.fix_image_raw(chat["meta_picture"])
                img = wx.ImageFromStream(cStringIO.StringIO(raw))
                namespace.update(chat_picture=img, chat_picture_raw=raw)
            for p in chat["participants"]:
                contact = p["contact"].copy()
                namespace["participants"].append(contact)
                contact.update(avatar_image_raw="", avatar_image_large_raw="")
                bmp = contact.get("avatar_bitmap")
                if not bmp:
                    bmp = skypedata.get_avatar(contact, conf.AvatarImageSize)
                    if bmp:
                        p["contact"]["avatar_bitmap"] = bmp # Cache resized
                if bmp:
                    size = conf.AvatarImageLargeSize
                    raw_large = skypedata.get_avatar_jpg(contact, size)
                    contact["avatar_image_raw"] = util.bitmap_to_raw(bmp)
                    contact["avatar_image_large_raw"] = raw_large

        # As HTML and TXT contain statistics in their headers before
        # messages, write out all messages to a temporary file first,
        # statistics will be available for the main file after parsing.
        # Cannot keep all messages in memory at once - very large chats
        # (500,000+ messages) can take gigabytes.
        tmpname = util.unique_path("%s.messages" % filename)
        tmpfile = open(tmpname, "w+")
        mtemplate = templates.CHAT_MESSAGES_HTML if is_html \
                    else templates.CHAT_MESSAGES_TXT
        step.Template(mtemplate, strip=False).stream(tmpfile, namespace)

        namespace["stats"] = stats = parser.get_collected_stats()
        namespace.update({
            "date1": stats["startdate"].strftime("%d.%m.%Y")
                     if stats.get("startdate") else "",
            "date2": stats["enddate"].strftime("%d.%m.%Y")
                     if stats.get("enddate") else "",
            "emoticons_used": filter(lambda e: hasattr(emoticons, e),
                                     parser.emoticons_unique),
            "message_count":  stats.get("messages", 0),
        })

        tmpfile.flush(), tmpfile.seek(0)
        namespace["message_buffer"] = iter(lambda: tmpfile.read(65536), "")
        template = templates.CHAT_HTML if is_html else templates.CHAT_TXT
        with open(filename, "w") as f:
            step.Template(template, strip=False).stream(f, namespace)
    finally:
        if tmpfile: util.try_until(tmpfile.close, count=1)
        if tmpname: util.try_until(lambda: os.unlink(tmpname), count=1)