Esempio n. 1
0
def minion_find(args):
    search_filter = args['<text>']
    find_any = False
    if args['find']:
        find_any = True
    match_files = brain.find_files(filter=search_filter, archives=args['--archives'],
                                   find_any=find_any)

    # Set archives if no finds...
    total = brain.get_total_file_count(args['--archives'])

    # Display results / total
    notes_home = brain.get_notes_home()
    match_template = "{matching} of {total} files match search " +\
        "'{search}' in directory {directory}"
    print(match_template.format(
        directory=notes_home,
        matching=len(match_files),
        search=','.join(search_filter),
        total=total))

    # Display results
    # print match_files
    brain.display_output(
        title=None,
        output=match_files,
        raw_files=args['--files'],
    )

    sys.exit(0)
Esempio n. 2
0
def minion_find(args):
    search_filter = args['<text>']
    find_any = False
    if args['find']:
        find_any = True
    match_files = brain.find_files(filter=search_filter,
                                   archives=args['--archives'],
                                   find_any=find_any)

    # Set archives if no finds...
    total = brain.get_total_file_count(args['--archives'])

    # Display results / total
    notes_home = brain.get_notes_home()
    match_template = "{matching} of {total} files match search " +\
        "'{search}' in directory {directory}"
    print match_template.format(directory=notes_home,
                                matching=len(match_files),
                                search=','.join(search_filter),
                                total=total)

    # Display results
    # print match_files
    brain.display_output(
        title=None,
        output=match_files,
        raw_files=args['--files'],
    )

    sys.exit(0)
Esempio n. 3
0
def minion_open(args):
    match_files = get_match_files(args)
    search_filter = args['<text>']

    if len(match_files) > 0:
        (_, filename) = brain.select_file(match_files, args['--max'])
        brain.open_in_editor(filename)
    else:
        brain.display_output(title=search_filter, output=match_files)
Esempio n. 4
0
def minion_open(args):
    match_files = get_match_files(args)
    search_filter = args['<text>']

    if len(match_files) > 0:
        (_, filename) = brain.select_file(match_files, args['--max'])
        brain.open_in_editor(filename)
    else:
        brain.display_output(title=search_filter, output=match_files)
Esempio n. 5
0
def minion_recent(args):
    ''' Show N most recent notes'''
    try:
        days_back = int(args['--days'])
    except (ValueError, TypeError):
        days_back = int(brain.get_setting('notes', 'default_recent_days'))

    match_files = get_match_files(args, days=days_back)
    recent_files = brain.list_recent(match_files)
    print "Notes modified in last %s days (most recent last):" % days_back
    brain.display_output(title=args['<text>'],
                         output=recent_files,
                         raw_files=args['--files'])
Esempio n. 6
0
def minion_recent(args):
    ''' Show N most recent notes'''
    try:
        days_back = int(args['--days'])
    except (ValueError, TypeError):
        days_back = int(brain.get_setting('notes', 'default_recent_days'))

    match_files = get_match_files(args, days=days_back)
    recent_files = brain.list_recent(match_files)
    print("Notes modified in last %s days (most recent last):" % days_back)
    brain.display_output(
        title=args['<text>'],
        output=recent_files,
        raw_files=args['--files'])
Esempio n. 7
0
def minion_log(args):
    '''Add a quick additional line to an existing (or new) Minion file.'''

    # Find the log file.
    params = {
        'filter': [args['<log>']],
        'archives': args['--archives'],
    }
    filename, match_files = brain.choose_file(**params)
    if not filename:
        title = ("Too many matches for log "
                 "function with keyword '{}'").format(args['<log>'])
        brain.display_output(title, match_files, max_display=10)
        return False

    params = {
        'filename': filename,
        'line': ' '.join(args['<comment>']),
    }

    brain.log_line_to_file(**params)
Esempio n. 8
0
def minion_log(args):
    '''Add a quick additional line to an existing (or new) Minion file.'''

    # Find the log file.
    params = {
        'filter': [args['<log>']],
        'archives': args['--archives'],
    }
    filename, match_files = brain.choose_file(**params)
    if not filename:
        title = ("Too many matches for log "
                 "function with keyword '{}'").format(args['<log>'])
        brain.display_output(title, match_files, max_display=10)
        return False

    params = {
        'filename': filename,
        'line': ' '.join(args['<comment>']),
    }

    brain.log_line_to_file(**params)
Esempio n. 9
0
def minion_collect(args):
    search_filter = args['<text>']
    if '<year>' in args:
        YEAR = args['<year>']
        match_files = get_match_files(args)
        collected_matches = brain.limit_to_year(YEAR, match_files)
        collection_title = 'Collected-%s-%s' % (YEAR, ' '.join(search_filter))

        print("%d/%d %s stories occur in year %s" % (
            len(collected_matches),
            len(match_files),
            search_filter,
            str(YEAR),
        ))
    else:
        collected_matches = match_files
        collection_title = 'Collected-%s' % (' '.join(search_filter))

    brain.display_output(collection_title, collected_matches)

    collected_string = collection_title

    sorted_matches = sorted(collected_matches, key=date_sort)

    for filename in sorted_matches:
        # Don't include past collections...
        if should_collect(filename):
            f = open(filename, 'r')
            lines = f.read()
            f.close()
            collected_string += '\n'
            collected_string += '\n'
            collected_string += lines

    collected_filename = brain.get_filename_for_title(collection_title)

    f = open(collected_filename, 'w')
    f.write(collected_string)
    f.close()
    brain.display_output('Created Collection', collected_filename)
Esempio n. 10
0
def minion_collect(args):
    search_filter = args['<text>']
    if '<year>' in args:
        YEAR = args['<year>']
        match_files = get_match_files(args)
        collected_matches = brain.limit_to_year(YEAR, match_files)
        collection_title = 'Collected-%s-%s' % (YEAR, ' '.join(search_filter))

        print "%d/%d %s stories occur in year %s" % (
            len(collected_matches),
            len(match_files),
            search_filter,
            str(YEAR),
        )
    else:
        collected_matches = match_files
        collection_title = 'Collected-%s' % (' '.join(search_filter))

    brain.display_output(collection_title, collected_matches)

    collected_string = collection_title

    sorted_matches = sorted(collected_matches, key=date_sort)

    for filename in sorted_matches:
        # Don't include past collections...
        if should_collect(filename):
            f = open(filename, 'r')
            lines = f.read()
            f.close()
            collected_string += '\n'
            collected_string += '\n'
            collected_string += lines

    collected_filename = brain.get_filename_for_title(collection_title)

    f = open(collected_filename, 'w')
    f.write(collected_string)
    f.close()
    brain.display_output('Created Collection', collected_filename)
Esempio n. 11
0
def minion_dates(args):
    '''Display all notes with dates in them and filtered by keywords.'''
    events = dict()
    match_files = get_match_files(args)
    for filename in match_files:
        content = brain.get_file_content(filename)
        dates = brain.get_unique_dates(content)
        if dates:
            for date in dates:
                try:
                    if date in events:
                        events[date].append(filename)
                    else:
                        events[date] = [filename]
                except ValueError:
                    # Date before 1900
                    _LOGGER.warn('Encountered date before 1900.')

    days_back = int(brain.get_setting('notes', 'default_recent_days'))
    recent_date = datetime.datetime.today() - datetime.timedelta(
        days=days_back)
    recent_date = recent_date.date()
    upcoming = dict()
    recent = dict()
    today = dict()
    # Sort the events into three sets - past, today and upcoming
    today_date = datetime.datetime.today().date()
    for key in events:
        date_str = key.strftime(get_date_format())
        if key > today_date:
            upcoming[date_str] = events[key]
        elif key == today_date:
            today[date_str] = events[key]
        elif key > recent_date:
            recent[date_str] = events[key]

    brain.display_output('Recent Dates', recent)
    print
    brain.display_output('Today', today)
    print
    brain.display_output('Upcoming Dates', upcoming)
    print
Esempio n. 12
0
def minion_dates(args):
    '''Display all notes with dates in them and filtered by keywords.'''
    events = dict()
    match_files = get_match_files(args)
    for filename in match_files:
        content = brain.get_file_content(filename)
        dates = brain.get_unique_dates(content)
        if dates:
            for date in dates:
                try:
                    if date in events:
                        events[date].append(filename)
                    else:
                        events[date] = [filename]
                except ValueError:
                    # Date before 1900
                    _LOGGER.warn('Encountered date before 1900.')

    days_back = int(brain.get_setting('notes', 'default_recent_days'))
    recent_date = datetime.datetime.today() - datetime.timedelta(days=days_back)
    recent_date = recent_date.date()
    upcoming = dict()
    recent = dict()
    today = dict()
    # Sort the events into three sets - past, today and upcoming
    today_date = datetime.datetime.today().date()
    for key in events:
        date_str = key.strftime(get_date_format())
        if key > today_date:
            upcoming[date_str] = events[key]
        elif key == today_date:
            today[date_str] = events[key]
        elif key > recent_date:
            recent[date_str] = events[key]

    brain.display_output('Recent Dates', recent)
    print()
    brain.display_output('Today', today)
    print()
    brain.display_output('Upcoming Dates', upcoming)
    print()