How to use memacs - 10 common examples

To help you get started, we’ve selected a few memacs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github novoid / Memacs / memacs / arbtt.py View on Github external
def __parse_sample(self, target, row):
        """
        parse a row of csv and write entry

        @param target: tag or category
        @param row: list of columns
        """
        tag, begin, end, duration = row

        timestamp = self.get_timerange(begin, end)
        duration = self.get_sec(duration)

        properties = OrgProperties(data_for_hashing=timestamp)
        properties.add('DURATION', duration)

        tags = []

        # remove colon from output
        if target.endswith(':'):
            target = target[:-1]
            tags.append(target)
        elif ':' in target:
            target = target.split(':')[0]

        output = target.capitalize()
        tags.append(tag)

        self._writer.write_org_subitem(
            timestamp=timestamp,
github novoid / Memacs / memacs / example.py View on Github external
# foo = self._get_config_option("foo")
        # bar = self._get_config_option("bar")

        # use logging.debug() for debug messages
        # use logging.error() for error messages
        # use logging.info() instead of print for informing user
        #
        # on an fatal error:
        # use logging.error() and sys.exit(1)

        timestamp = OrgFormat.date(time.gmtime(0), show_time=True)
        # note: timestamp has to be a struct_time object

        # Orgproperties
        # Option 1: no properties given, specify argument for hashing data
        properties = OrgProperties("hashing data :ALKJ!@# should be unique")
        # Option 2: add properties which are all-together unique
        # properties.add("Category","fun")
        # properties.add("from","me@example.com")
        # properties.add("body","foo")

        self._writer.write_org_subitem(timestamp=timestamp,
                                       output="foo",
                                       properties=properties)

        # writes following:
        #** <1970-01-01 Thu 00:00> foo
        #   :PROPERTIES:
        #   :ID:             da39a3ee5e6b4b0d3255bfef95601890afd80709
        #   :END:

        notes = "bar notes\nfoo notes"
github novoid / Memacs / memacs / ical.py View on Github external
import logging
import time
from memacs.lib.memacs import Memacs
from orgformat import OrgFormat
from memacs.lib.orgproperty import OrgProperties
from memacs.lib.reader import CommonReader

try:
    from icalendar import Calendar
except ImportError as e:
    print("please install python package \"icalendar\"")
    print(e)
    sys.exit(3)


class CalendarMemacs(Memacs):
    def _parser_add_arguments(self):
        self._parser.add_argument("-c", "--calendar-url", dest="calendar_url",
                        help="url to calendar")

        self._parser.add_argument("-cf", "--calendar-file",
                                  dest="calendar_file",
                                  help="path to calendar")

        self._parser.add_argument(
            "-x", "--exclude", dest="excludelist",
            help="path to one or more folders seperated with \"|\"," + \
                "i.e.:\"/path/to/folder1|/path/to/folder2|..\"")

    def _parser_parse_args(self):
        Memacs._parser_parse_args(self)
github novoid / Memacs / memacs / csv.py View on Github external
def _parser_parse_args(self):
        """
        overwritten method of class Memacs

        all additional arguments are parsed in here
        """
        Memacs._parser_parse_args(self)

        if self._args.fieldnames:
            self._args.fieldnames = [name.strip() for name in self._args.fieldnames.split(',')]
github novoid / Memacs / memacs / sms_superbackup.py View on Github external
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)
github novoid / Memacs / memacs / phonecalls_superbackup.py View on Github external
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)
github novoid / Memacs / memacs / svn.py View on Github external
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)
github novoid / Memacs / memacs / sms.py View on Github external
## 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)
github novoid / Memacs / memacs / phonecalls.py View on Github external
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 or 0,
                                              ))
        except SAXParseException:
            logging.error("No correct XML given")
            sys.exit(1)
github novoid / Memacs / memacs / svn.py View on Github external
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)