How to use the memacs.lib.orgproperty.OrgProperties function in memacs

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 / sms.py View on Github external
## FIXXME: this is a horrible dumb brute-force algorithm.
                    ##         In case of bad performance, this can be optimized dramtically
                    sms_body = sms_body.replace(emoji, self.EMOJI_ENCLOSING_CHARACTER + \
                                                self.EMOJIS[emoji] + self.EMOJI_ENCLOSING_CHARACTER).replace('\n', '⏎')

                if sms_subject != "null":
                    # in case of MMS we have a subject
                    output += sms_subject
                    notes = sms_body
                else:
                    output += sms_body
                    notes = ""

                timestamp = OrgFormat.date(time.gmtime(sms_date), show_time=True)
                data_for_hashing = output + timestamp + notes
                properties = OrgProperties(data_for_hashing=data_for_hashing)

                properties.add("NUMBER", sms_address)
                properties.add("NAME", contact_name)

                self._writer.write_org_subitem(output=output,
                                               timestamp=timestamp,
                                               note=notes,
                                               properties=properties)
github novoid / Memacs / memacs / filenametimestamps.py View on Github external
def __write_file(self, file, link, timestamp):
        """
        write entry to org file (omit replacement of spaces in file names)
        """
        output = OrgFormat.link(link="file:" + link, description=file, replacespaces=False)
        properties = None
        if not self._args.omit_drawers:
            # we need optional data for hashing due it can be, that more
            # than one file have the same timestamp
            properties = OrgProperties(data_for_hashing=output)
        self._writer.write_org_subitem(timestamp=timestamp,
                                       output=output,
                                       properties=properties)
github novoid / Memacs / memacs / lib / mailparser.py View on Github external
# Read only these fields
        use_headers = ["To",
                       "Date",
                       "From",
                       "Subject",
                       "Reply-To",
                       "Newsgroups",
                       "Cc",
                       ]
        # These fields are added, if found to :PROPERTIES: drawer
        not_properties = ["Date",
                          "Subject",
                          "From"
                          ]

        properties = OrgProperties()
        headers = {}

        logging.debug("Message items:")
        logging.debug(list(msg.items()))

        msg_id = None

        # fill headers and properties
        for key, value in list(msg.items()):
            value = value.replace("\r", "")
            if key in use_headers:
                headers[key] = value
                if key not in not_properties:
                    properties.add(key, MailParser.get_value_or_empty_str(headers, key, True))

            if key.upper() == "MESSAGE-ID":
github novoid / Memacs / memacs / example.py View on Github external
# 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"

        p = OrgProperties(data_for_hashing="read comment below")
        # if a hash is not unique only with its :PROPERTIES: , then
        # set data_for_hasing string additional information i.e. the output
        # , which then makes the hash really unique
        #
        # if you *really*, *really* have already a unique id,
        # then you can call following method:
        # p.set_id("unique id here")

        p.add("DESCRIPTION", "foooo")
        p.add("foo-property", "asdf")

        tags = ["tag1", "tag2"]

        self._writer.write_org_subitem(timestamp=timestamp,
                                       output="bar",
                                       note=notes,
github novoid / Memacs / memacs / simplephonelogs.py View on Github external
# check if we've found a lunch-break (first wifi-office between 11:30-13:00 where not office for > 17min)
                if e_time.time() > datetime.time(11, 30) and e_time.time() < datetime.time(13, 00) and e_last_opposite_occurrence:
                    if e_last_opposite_occurrence.date() == e_time.date() and in_between_s > (17 * 60) and in_between_s < (80 * 60):
                        office_lunchbreak = [e_last_opposite_occurrence.time(), e_time.time()]

        # handle special case: boot without previous shutdown = crash
        if (e_name == 'boot') and \
                (e_last_occurrence and e_last_opposite_occurrence) and \
                (e_last_occurrence > e_last_opposite_occurrence):
            # last boot is more recent than last shutdown -> crash has happened
            last_info = ' after crash'
            in_between_hms = ''
            in_between_s = ''
            ignore_occurrence = True

        properties = OrgProperties()
        if in_between_s == 0:  # omit in-between content of property when it is zero
            in_between_s = ''
            in_between_hms = ''
        properties.add("IN-BETWEEN", in_between_hms)
        properties.add("IN-BETWEEN-S", str(in_between_s))
        properties.add("BATT-LEVEL", e_batt)
        properties.add("UPTIME", OrgFormat.hms_from_sec(int(e_uptime)))
        properties.add("UPTIME-S", e_uptime)

        if e_name == 'wifi-office-end' and office_lunchbreak:
            properties.add("OFFICE-SUMMARY",
                           e_last_opposite_occurrence.strftime('| %Y-%m-%d | %a ') +
                           prev_office_first_begin.strftime('| %H:%M ') +
                           office_lunchbreak[0].strftime('| %H:%M ') +
                           office_lunchbreak[1].strftime('| %H:%M ') +
                           e_time.strftime('| %H:%M | | |'))
github novoid / Memacs / memacs / battery.py View on Github external
def _handle_battery(self, bat):
        """
        handle single battery, e.g. BAT0
        """

        # calculate watt usage
        consumption = float(bat.current_now / 1000000.0 *
                            bat.voltage_now / 1000000.0)

        timestamp = OrgFormat.date(datetime.datetime.now(), show_time=True)
        output = self._args.output_format.format(battery=bat)

        properties = OrgProperties(data_for_hashing=timestamp)
        properties.add("CYCLE_COUNT", bat.cycle_count)
        properties.add("CAPACITY", '%s%%' % bat.capacity)
        properties.add("STATUS", bat.status.lower())

        if consumption:
            properties.add("CONSUMPTION", '%.1f W' % consumption)

        self._writer.write_org_subitem(timestamp=timestamp,
                                       output=output,
                                       properties=properties)
github novoid / Memacs / memacs / lib / orgwriter.py View on Github external
def write_org_subitem(self,
                          timestamp,
                          output,
                          note="",
                          properties=OrgProperties(),
                          tags=None):
        """
        Writes an org item line.

        i.e:**  <output> ::\n
               :PROPERTIES:
               
               :ID: -generated id-
               :END:

        if an argument -a or --append is given,
        then a desicion regarding the :ID: is made if the item has to be
        written to file

        @param timestamp: str/unicode or False (for no time-stamp)
        @param output: st tar/unicode</output>