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 or 0, )) except SAXParseException: logging.error("No correct XML given") sys.exit(1)
def test_parser(self): result_file = os.path.dirname(os.path.abspath( __file__)) + os.path.sep + "sample-phonelog-result-TEMP.org" argv = "-f " + self.test_file + \ " --output " + result_file localmodule = SimplePhoneLogsMemacs(argv=argv.split()) localmodule.handle_main() result_from_module = CommonReader.get_data_from_file(result_file) result_from_module_without_header_and_last_line = u'' for line in result_from_module.split('\n'): if line.startswith(u'* successfully parsed ') or \ line.startswith(u'#') or \ line.startswith(u'* '): pass else: result_from_module_without_header_and_last_line += line + '\n' ## self.reference_result is defined below! self.assertEqual(result_from_module_without_header_and_last_line, self.reference_result) os.remove(result_file)
def test_parser(self): result_file = os.path.dirname( os.path.abspath(__file__)) + os.path.sep + "sample-phonelog-result-TEMP.org" argv = "-f " + self.test_file + \ " --output " + result_file localmodule = SimplePhoneLogsMemacs(argv = argv.split()) localmodule.handle_main() result_from_module = CommonReader.get_data_from_file(result_file) result_from_module_without_header_and_last_line = u'' for line in result_from_module.split('\n'): if line.startswith(u'* successfully parsed ') or \ line.startswith(u'#') or \ line.startswith(u'* '): pass else: result_from_module_without_header_and_last_line += line + '\n' ## self.reference_result is defined below! self.assertEqual(result_from_module_without_header_and_last_line, self.reference_result) os.remove(result_file)
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)
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))
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)
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)
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('&#', 'EnCoDiNgHaCk42') + '\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)
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)
def get_result_from_file(self): """reads out the resulting file and returns its content without header lines, main heading, last finish message, and empty lines""" result_from_module = CommonReader.get_data_from_file(self.result_file) result_from_module_without_header_and_last_line = u'' ## remove header and last line (which includes execution-specific timing) for line in result_from_module.split('\n'): if line.startswith(u'* successfully parsed ') or \ line.startswith(u'#') or \ line.startswith(u'* '): pass else: line = line.rstrip() result_from_module_without_header_and_last_line += line + '\n' return result_from_module_without_header_and_last_line.strip()
def test_file_no_path(self): try: CommonReader.get_data_from_file("") self.assertTrue(False, "false path failed") except SystemExit: pass