コード例 #1
0
ファイル: sleep_cycle.py プロジェクト: durden/dayonetools
def _create_entry(entry, directory, verbose):
    """
    Create/write day one file with given sleep cycle entry

    entry should be a named tuple
    """

    # Create unique uuid without any specific machine information
    # (uuid() vs. uuid()) and strip any '-' characters to be
    # consistent with dayone format.
    uuid_str = re.sub('-', '', str(uuid.uuid4()))

    file_name = '%s.doentry' % (uuid_str)
    full_file_name = os.path.join(directory, file_name)

    entry_dict = entry._asdict()
    entry_dict['uuid_str'] = uuid_str

    day_str, time_str = entry_dict['Start'].split(' ')
    hour, minute, second = time_str.split(':')
    entry_dict['sleep_start'] = convert_to_dayone_date_string(day_str,
                                                              hour,
                                                              minute,
                                                              second)

    with open(full_file_name, 'w') as file_obj:
        text = ENTRY_TEMPLATE.format(entry_title=HEADER_FOR_DAYONE_ENTRIES,
                                     **entry_dict)
        file_obj.write(text)

    if verbose:
        print 'Created entry for %s: %s' % (entry.Start, file_name)
コード例 #2
0
ファイル: idonethis.py プロジェクト: jotefa/dayonetools
def _create_dayone_entry(date, entries, directory, verbose):
    """Create single dayone journal entry for list of given entries"""

    entry_text = "\n".join(entries)
    date = convert_to_dayone_date_string(date)

    # Create unique uuid without any specific machine information (uuid() vs.
    # uuid()) and strip any '-' characters to be consistent with dayone format.
    uuid_str = re.sub("-", "", str(uuid.uuid4()))

    file_name = "%s.doentry" % (uuid_str)
    full_file_name = os.path.join(directory, file_name)

    with open(full_file_name, "w") as file_obj:
        text = ENTRY_TEMPLATE.format(
            entry_title=HEADER_FOR_DAYONE_ENTRIES, date=date, entry_text=entry_text, uuid_str=uuid_str
        )
        file_obj.write(text)

    if verbose:
        print "Created entry for %s: %s" % (date, file_name)
コード例 #3
0
def _create_dayone_entry(date, entries, directory, verbose):
    """Create single dayone journal entry for list of given entries"""

    entry_text = '\n'.join(entries)
    date = convert_to_dayone_date_string(date)

    # Create unique uuid without any specific machine information (uuid() vs.
    # uuid()) and strip any '-' characters to be consistent with dayone format.
    uuid_str = re.sub('-', '', str(uuid.uuid4()))

    file_name = '%s.doentry' % (uuid_str)
    full_file_name = os.path.join(directory, file_name)

    with open(full_file_name, 'w') as file_obj:
        text = ENTRY_TEMPLATE.format(entry_title=HEADER_FOR_DAYONE_ENTRIES,
                                     date=date,
                                     entry_text=entry_text,
                                     uuid_str=uuid_str)
        file_obj.write(text)

    if verbose:
        print 'Created entry for %s: %s' % (date, file_name)
コード例 #4
0
ファイル: habit_list.py プロジェクト: durden/dayonetools
def create_habitlist_entry(directory, day_str, habits, verbose):
    """Create day one file entry for given habits, date pair"""

    # Create unique uuid without any specific machine information
    # (uuid() vs.  uuid()) and strip any '-' characters to be
    # consistent with dayone format.
    uuid_str = re.sub('-', '', str(uuid.uuid4()))

    file_name = '%s.doentry' % (uuid_str)
    full_file_name = os.path.join(directory, file_name)

    date = convert_to_dayone_date_string(day_str)
    habits = _habits_to_markdown(habits)

    entry = {'entry_title': HEADER_FOR_DAYONE_ENTRIES,
              'habits': habits,'date': date, 'uuid_str': uuid_str}

    with open(full_file_name, 'w') as file_obj:
        text = ENTRY_TEMPLATE.format(**entry)
        file_obj.write(text)

    if verbose:
        print 'Created entry for %s: %s' % (date, file_name)
コード例 #5
0
ファイル: habit_list.py プロジェクト: jotefa/dayonetools
def create_habitlist_entry(directory, day_str, habits, verbose):
    """Create day one file entry for given habits, date pair"""

    # Create unique uuid without any specific machine information
    # (uuid() vs.  uuid()) and strip any '-' characters to be
    # consistent with dayone format.
    uuid_str = re.sub('-', '', str(uuid.uuid4()))

    file_name = '%s.doentry' % (uuid_str)
    full_file_name = os.path.join(directory, file_name)

    date = convert_to_dayone_date_string(day_str)
    habits = _habits_to_markdown(habits)

    entry = {'entry_title': HEADER_FOR_DAYONE_ENTRIES,
              'habits': habits,'date': date, 'uuid_str': uuid_str}

    with open(full_file_name, 'w') as file_obj:
        text = ENTRY_TEMPLATE.format(**entry)
        file_obj.write(text)

    if verbose:
        print 'Created entry for %s: %s' % (date, file_name)