コード例 #1
0
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
        for l in assetfile_links:
            # Avoid Markdown file removal
            if not (l.endswith(ext)):
コード例 #2
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)",