def getAssetsFolder():
    """
    Get Assets Upload Folder from config

    Returns:
        str: Asset Folder for md Notes
    """
    my_notes = Search()
    notes_path = my_notes.getNotesPath()
    assets_path = os.path.join(notes_path, ASSETS_FOLDER)
    if not (os.path.exists(assets_path)):
        os.mkdir(assets_path)
    return assets_path
def get_mdfiles_list_content():
    """
    Get markdown links in unordered markdown list

    Returns:
        str: Markdown unordered list

    """
    ns = Search()
    output = list()
    files = os.getenv('files').split('|')
    for f in files:
        link_title = ns.getNoteTitle(f)
        file_name = os.path.basename(f)
        output.append('* [' + link_title + '](' + pathname2url(file_name) + ')')
    return("\n".join(output))
def get_mdfiles_list_content() -> str:
    """
    Get markdown links in unordered markdown list

    Returns:

        str: Markdown unordered list

    """
    ns = Search()
    output = list()
    files = os.getenv('files').split(
        '|')  # one or list of md file paths from prev wf step
    for f in files:
        link_title = ns.getNoteTitle(f)
        file_name = os.path.basename(f)
        output.append(f'* [{link_title}]({pathname2url(file_name)})')
    return ("\n".join(output))
def getFileQuery(q):
    return q.split('|') if '|' in q else [q, str()]


def getAssetsLinks(parent_path, p):
    def is_in_notes(f_path):
        return not (str(f_path).startswith('..')) and not (
            str(f_path).startswith('/'))

    with open(p, 'r') as f:
        content = f.read()
    matches = re.findall(r'\[.*\]\((.*)\)', content)
    return [os.path.join(parent_path, m) for m in matches if is_in_notes(m)]


mn = Search()

# Load extentions env variables from settings
ext = mn.getNotesExtension()
# Get all files which needs to be deleted from input
files_to_delete = sys.argv[1:]

return_text = str()
for query in files_to_delete:
    file_path, last_query = getFileQuery(query)
    if os.path.isfile(file_path) and file_path.endswith(ext):
        file_name = os.path.basename(file_path)
        # Search for links to other assets and delete each file
        parent = mn.getNotesPath()
        assetfile_links = getAssetsLinks(parent, file_path)
        is_assetfile_deleted = False
#!/usr/bin/python
# -*- coding: utf-8 -*-

from Alfred import Items, Tools
from MyNotes import Search

query = Tools.getArgv(1)
bmt = Tools.getEnv('bookmark_tag')
bookmark_tag = bmt if bmt.startswith('#') else '#' + bmt

search_terms = '{0}&{1}'.format(bookmark_tag, query) if query else bookmark_tag

notes = Search()
search_terms, _ = notes.get_search_config(search_terms)
matches = notes.url_search(search_terms)

alf = Items()
if matches:
    for m in matches:
        note_title = m.get('title')
        note_path = m.get('path')
        links = m.get('links')
        for l in links:
            url_title = l.get('url_title')
            url = l.get('url')
            # subtitle = '%s > %s' % (url_title, url) if url_title != url else url
            subtitle = 'NOTE: {0} URL: {1}...'.format(note_title, url[:30])
            alf.setItem(
                title=url_title,
                subtitle=subtitle,
                arg=url,
Beispiel #6
0
#!/usr/bin/env python3

import os
import sys
from urllib.request import pathname2url

from MyNotes import Search

query = sys.argv[1]  # File path to MD Note
file_name = os.path.basename(query)
ms = Search()
title = ms.getNoteTitle(query)
output = f"[{title}]({pathname2url(file_name)})"
sys.stdout.write(output)
Beispiel #7
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-

from unicodedata import normalize

from Alfred3 import Items as Items
from Alfred3 import Keys as K
from Alfred3 import Tools as Tools
from MyNotes import Search

# create MD search object
md = Search()

# Get environment variables
ext = md.getNotesExtension()
query = normalize('NFC', Tools.getArgv(1))  # Tag name

if query is str():
    # Tag Search and sort based on tag name
    tag_results = md.tagSearch(query, 'tag', reverse=False)
else:
    # Tag Search and sort based on number of Hits
    tag_results = md.tagSearch(query, 'count', reverse=True)

wf = Items()

if bool(tag_results):
    for tag, counter in tag_results.items():
        wf.setItem(
            title=f'{tag}',
            subtitle=f"{counter} Hit(s), ({K.CMD} to paste tag into frontmost app)",
Beispiel #8
0
#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys
import urllib

from Alfred import Items as Items
from Alfred import Tools as Tools
from MyNotes import Search

# create MD search object
md_search = Search()

# Load Env variables
query = Tools.getArgv(1)
# TODO: For testing, delete 3 lines
#query = "Äsch".encode('utf-8')
# sys.stderr.write(query)

# Get Search config with AND and OR
search_terms, search_type = md_search.get_search_config(query)

# create WF object
wf = Items()

# exec search if search terms were entered
if len(search_terms) > 0:
    sorted_file_list = md_search.notes_search(search_terms, search_type)
# get full list of file in case no search was entered
else:
    sorted_file_list = md_search.getFilesListSorted()