예제 #1
0
파일: mbox.py 프로젝트: Daniel1234/Memacs
    def _main(self):
        """
        get's automatically called from Memacs class
        """
        if self._args.mail_file:
            data = CommonReader.get_data_from_file(self._args.mail_file)
            data = data.decode("utf-8", "replace")
            data = data.encode("utf-8")
            self.__read_mails_and_write(data)

        elif self._args.news_file:
            data = CommonReader.get_data_from_file(self._args.news_file)
            data = data.decode("utf-8", "replace")
            data = data.encode("utf-8")
            self.__read_news_and_write(data)
예제 #2
0
    def _main(self):
        """
        gets called automatically from Memacs class.
        read the lines from phonecalls backup xml file,
        parse and write them to org file
        """

        data = CommonReader.get_data_from_file(self._args.smsxmlfile)

        try:
            xml.sax.parseString(
                data.encode('utf-8'),
                PhonecallsSaxHandler(
                    self._writer,
                    self._args.ignore_incoming,
                    self._args.ignore_outgoing,
                    self._args.ignore_missed,
                    self._args.ignore_voicemail,
                    self._args.ignore_rejected,
                    self._args.ignore_refused,
                    self._args.minimum_duration,
                ))
        except SAXParseException:
            logging.error("No correct XML given")
            sys.exit(1)
예제 #3
0
    def _main(self):
        """
        gets called automatically from Memacs class.
        read the lines from phonecalls backup xml file,
        parse and write them to org file
        """

        self._parse_data(CommonReader.get_data_from_file(self._args.phonelogfile))
예제 #4
0
파일: ical.py 프로젝트: stvol/Memacs
    def _main(self):
        # getting data
        if self._args.calendar_file:
            data = CommonReader.get_data_from_file(self._args.calendar_file,
                                                   encoding=None)
        elif self._args.calendar_url:
            data = CommonReader.get_data_from_url(self._args.calendar_url)

        # read and go through calendar
        cal = Calendar.from_ical(data)
        for component in cal.walk():
            if component.name == "VCALENDAR":
                self.__handle_vcalendar(component)
            elif component.name == "VEVENT":
                self.__handle_vevent(component)
            else:
                logging.debug("Not handling component: " + component.name)
예제 #5
0
파일: ical.py 프로젝트: M1lan/Memacs
    def _main(self):
        # getting data
        if self._args.calendar_file:
            data = CommonReader.get_data_from_file(self._args.calendar_file,
            encoding=None)
        elif self._args.calendar_url:
            data = CommonReader.get_data_from_url(self._args.calendar_url)

        # read and go through calendar
        cal = Calendar.from_ical(data)
        for component in cal.walk():
            if component.name == "VCALENDAR":
                self.__handle_vcalendar(component)
            elif component.name == "VEVENT":
                self.__handle_vevent(component)
            else:
                logging.debug("Not handling component: " + component.name)
예제 #6
0
    def _main(self):
        """
        gets called automatically from Memacs class.
        read the lines from phonecalls backup xml file,
        parse and write them to org file
        """

        self._parse_data(CommonReader.get_data_from_file(self._args.phonelogfile))
예제 #7
0
파일: svn.py 프로젝트: Daniel1234/Memacs
    def _main(self):
        """
        get's automatically called from Memacs class
        read the lines from svn xml file, parse and write them to org file
        """

        # read file
        if self._args.svnlogxmlfile:
            logging.debug("using as %s input_stream", self._args.svnlogxmlfile)
            data = CommonReader.get_data_from_file(self._args.svnlogxmlfile)
        else:
            logging.info("Using stdin as input_stream")
            data = CommonReader.get_data_from_stdin()

        try:
            xml.sax.parseString(data.encode('utf-8'),
                                SvnSaxHandler(self._writer,
                                              self._args.grepauthor))
        except SAXParseException:
            logging.error("No correct XML given")
            sys.exit(1)
예제 #8
0
파일: svn.py 프로젝트: serycjon/Memacs
    def _main(self):
        """
        get's automatically called from Memacs class
        read the lines from svn xml file, parse and write them to org file
        """

        # read file
        if self._args.svnlogxmlfile:
            logging.debug("using as %s input_stream", self._args.svnlogxmlfile)
            data = CommonReader.get_data_from_file(self._args.svnlogxmlfile)
        else:
            logging.info("Using stdin as input_stream")
            data = CommonReader.get_data_from_stdin()

        try:
            xml.sax.parseString(data.encode('utf-8'),
                                SvnSaxHandler(self._writer,
                                              self._args.grepauthor))
        except SAXParseException:
            logging.error("No correct XML given")
            sys.exit(1)
예제 #9
0
파일: rss.py 프로젝트: Daniel1234/Memacs
    def _main(self):
        """
        get's automatically called from Memacs class
        """
        # getting data
        if self._args.file:
            data = CommonReader.get_data_from_file(self._args.file)
        elif self._args.url:
            data = CommonReader.get_data_from_url(self._args.url)

        rss = feedparser.parse(data)
        logging.info("title: %s", rss['feed']['title'])
        logging.info("there are: %d entries", len(rss.entries))

        for item in rss.entries:
            logging.debug(item)
            output, note, properties, tags, timestamp = \
                self.__get_item_data(item)
            self._writer.write_org_subitem(output=output,
                                           timestamp=timestamp,
                                           note=note,
                                           properties=properties,
                                           tags=tags)
예제 #10
0
    def __get_files(self, cur_path):
        """
        Reads a mail, let Mailparser parse the mail,
        write to outputfile

        @param cur_path: string contains the path to maildir email
        """
        listing = os.listdir(cur_path)
        for maildir_file in listing:
            path = cur_path + '/' + maildir_file
            data = CommonReader.get_data_from_file(path)
            data = data.decode("utf-8", "replace")
            data = data.encode("utf-8")
            self.__read_mails_and_write(data)
예제 #11
0
파일: rss.py 프로젝트: serycjon/Memacs
    def _main(self):
        """
        get's automatically called from Memacs class
        """
        # getting data
        if self._args.file:
            data = CommonReader.get_data_from_file(self._args.file)
        elif self._args.url:
            data = CommonReader.get_data_from_url(self._args.url)

        rss = feedparser.parse(data)
        logging.info("title: %s", rss['feed']['title'])
        logging.info("there are: %d entries", len(rss.entries))

        for item in rss.entries:
            logging.debug(item)
            output, note, properties, tags, timestamp = \
                self.__get_item_data(item)
            self._writer.write_org_subitem(output=output,
                                           timestamp=timestamp,
                                           note=note,
                                           properties=properties,
                                           tags=tags)
예제 #12
0
    def _main(self):
        """
        get's automatically called from Memacs class
        """
        if self._args.file:
            data = CommonReader.get_data_from_file(self._args.file)
        elif self._args.url:
            data = CommonReader.get_data_from_url(self._args.url)

        section = self._args.section
        conf = self._args.ini
        self.__get_data_of_conf(section, conf)
        split = self._args.splitcriterion

        data = data.decode("utf-8", "replace")
        try:
            xml.sax.parseString(data.encode('utf-8'),
                                XmlSaxHandler(self._writer,
                                              self.__paras,
                                              split))

        except SAXParseException:
            logging.error("No correct XML given")
            sys.exit(1)
예제 #13
0
    def _main(self):
        """
        get's automatically called from Memacs class
        read the lines from sms backup xml file,
        parse and write them to org file
        """

        ## replace HTML entities "&#" in original file to prevent XML parser from worrying:
        temp_xml_file = tempfile.mkstemp()[1]
        line_number = 0
        logging.debug("tempfile [%s]", str(temp_xml_file))
        with codecs.open(temp_xml_file, 'w', encoding='utf-8') as outputhandle:
            for line in codecs.open(self._args.smsxmlfile,
                                    'r',
                                    encoding='utf-8'):
                try:
                    ## NOTE: this is a dirty hack to prevent te XML parser from complainaing about
                    ##       encoding issues of UTF-8 encoded emojis. Will be reverted when parsing sms_body
                    outputhandle.write(
                        line.replace(u'&#', u'EnCoDiNgHaCk42') + u'\n')
                except IOError as e:
                    print "tempfile line " + str(line_number) + " [" + str(
                        temp_xml_file) + "]"
                    print "I/O error({0}): {1}".format(e.errno, e.strerror)
                except ValueError as e:
                    print "tempfile line " + str(line_number) + " [" + str(
                        temp_xml_file) + "]"
                    print "Value error: {0}".format(e)
                    #print "line [%s]" % str(line)
                except:
                    print "tempfile line " + str(line_number) + " [" + str(
                        temp_xml_file) + "]"
                    print "Unexpected error:", sys.exc_info()[0]
                    raise

        data = CommonReader.get_data_from_file(temp_xml_file)

        try:
            xml.sax.parseString(
                data.encode('utf-8'),
                SmsSaxHandler(self._writer, self._args.ignore_incoming,
                              self._args.ignore_outgoing, self._numberdict))
        except SAXParseException:
            logging.error("No correct XML given")
            sys.exit(1)
        else:
            os.remove(temp_xml_file)
예제 #14
0
파일: sms.py 프로젝트: awieser/Memacs
    def _main(self):
        """
        get's automatically called from Memacs class
        read the lines from sms backup xml file,
        parse and write them to org file
        """

        data = CommonReader.get_data_from_file(self._args.smsxmlfile)

        try:
            xml.sax.parseString(
                data.encode('utf-8'),
                SmsSaxHandler(self._writer, self._args.ignore_incoming,
                              self._args.ignore_outgoing))
        except SAXParseException:
            logging.error("No correct XML given")
            sys.exit(1)
예제 #15
0
파일: sms.py 프로젝트: eduenez/Memacs
    def _main(self):
        """
        get's automatically called from Memacs class
        read the lines from sms backup xml file,
        parse and write them to org file
        """

        data = CommonReader.get_data_from_file(self._args.smsxmlfile)

        try:
            xml.sax.parseString(data.encode('utf-8'),
                                SmsSaxHandler(self._writer,
                                              self._args.ignore_incoming,
                                              self._args.ignore_outgoing))
        except SAXParseException:
            logging.error("No correct XML given")
            sys.exit(1)
예제 #16
0
파일: sms.py 프로젝트: easeflyer/Memacs
    def _main(self):
        """
        get's automatically called from Memacs class
        read the lines from sms backup xml file,
        parse and write them to org file
        """

        ## replace HTML entities "&#" in original file to prevent XML parser from worrying:
        temp_xml_file = tempfile.mkstemp()[1]
        line_number = 0
        logging.debug("tempfile [%s]", str(temp_xml_file))
        with codecs.open(temp_xml_file, 'w', encoding='utf-8') as outputhandle:
            for line in codecs.open(self._args.smsxmlfile, 'r', encoding='utf-8'):
                try:
                    ## NOTE: this is a dirty hack to prevent te XML parser from complainaing about
                    ##       encoding issues of UTF-8 encoded emojis. Will be reverted when parsing sms_body
                    outputhandle.write(line.replace(u'&#', u'EnCoDiNgHaCk42') + u'\n')
                except IOError as e:
                    print "tempfile line " + str(line_number) +  " [" + str(temp_xml_file) + "]"
                    print "I/O error({0}): {1}".format(e.errno, e.strerror)
                except ValueError as e:
                    print "tempfile line " + str(line_number) +  " [" + str(temp_xml_file) + "]"
                    print "Value error: {0}".format(e)
                    #print "line [%s]" % str(line)
                except:
                    print "tempfile line " + str(line_number) +  " [" + str(temp_xml_file) + "]"
                    print "Unexpected error:", sys.exc_info()[0]
                    raise

        data = CommonReader.get_data_from_file(temp_xml_file)

        try:
            xml.sax.parseString(data.encode('utf-8'),
                                SmsSaxHandler(self._writer,
                                              self._args.ignore_incoming,
                                              self._args.ignore_outgoing,
                                              self._numberdict))
        except SAXParseException:
            logging.error("No correct XML given")
            sys.exit(1)
        else:
            os.remove(temp_xml_file)
예제 #17
0
    def _main(self):
        """
        gets called automatically from Memacs class.
        read the lines from phonecalls backup xml file,
        parse and write them to org file
        """

        data = CommonReader.get_data_from_file(self._args.smsxmlfile)

        try:
            xml.sax.parseString(data.encode('utf-8'),
                                PhonecallsSaxHandler(self._writer,
                                              self._args.ignore_incoming,
                                              self._args.ignore_outgoing,
                                              self._args.ignore_missed,
                                              self._args.ignore_cancelled,
                                              self._args.minimum_duration,
                                              ))
        except SAXParseException:
            logging.error("No correct XML given")
            sys.exit(1)