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
Exemplo n.º 5
0
#!/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,
Exemplo n.º 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)
Exemplo n.º 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)",
Exemplo n.º 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()
Exemplo n.º 9
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import os
from urllib.request import pathname2url

from Alfred3 import Items, Tools
from MyNotes import Search

# Get NotePath as path_query env variable
note_path = Tools.getEnv("path_query1")
# Get query used in search markdown notes as path_query env variable
query = Tools.getEnv("path_query2")
md_notes = Search()
# Get NoteTitle for specific note
note_title = md_notes.getNoteTitle(note_path)
file_name = pathname2url(os.path.basename(note_path))
# If query in notes search was empty subtitle uses following string
back_query = "<EMPTY>" if not query else query

# Actions in ScriptFilter menu data
ACTIONS = [
    {
        "title": "Back",
        "subtitle": f"Back to Search with query: {back_query}",
        "arg": f"back|{query}",
        "icon": "icons/back.png",
        "visible": True
    },
    {
        "title": "Markdown Link",
Exemplo n.º 10
0
    to_replace = ['/', '\\', ':', '|']
    tmp = f.decode('utf-8').strip()
    # tmp = f.strip()
    for i in to_replace:
        tmp = tmp.replace(i, '-')
    # return tmp
    return tmp.encode('utf-8')


def writeMarkdown(md_content, md_path):
    with open(md_path, "w+") as f:
        f.write(md_content.encode('utf-8'))
        # f.write(md_content)


mn = Search()
ext = mn.getNotesExtension()
p = mn.getNotesPath()
argv = Tools.getArgv(1)
url = argv if argv.startswith('http://') or argv.startswith(
    'https://') else str()

# TODO: When HTML is not fetchable, the URL will be used.
# Fix formatting from <url> to markdown url [title](url)

if url:
    Tools.notify('Fetch URL...', 'The Note will be opened after the import...')
    markdown = Markdown(url)
    today = markdown.getTodayDate(fmt="%d.%m.%Y")
    today_time = markdown.getTodayDate(fmt="%d-%m-%Y %H-%M")
    md = markdown.getMarkdownContent()
Exemplo n.º 11
0
#!/usr/bin/python3

import os
import sys

from Alfred3 import Tools
from MyNotes import Search

f_path = Tools.getArgv(1)  # Path to MD Note
s = Search()
url_scheme_path = s.getUrlScheme(f_path)
filename = os.path.basename(f_path)
md_link = f"[{filename}]({url_scheme_path})"
sys.stdout.write(md_link)
Exemplo n.º 12
0
#!/usr/bin/python

import os
import sys

from Alfred import Tools
from MyNotes import Search

f_path = Tools.getArgv(1)

url_scheme_path = Search.getUrlScheme(f_path)
filename = os.path.basename(f_path)
# url_scheme_path = MyNotes.Search.getUrlScheme(filename)
md_link = "[{0}]({1})".format(filename, url_scheme_path)

sys.stdout.write(md_link)
#!/usr/bin/python

from Alfred import Items, Tools
from MyNotes import Search

query = Tools.getArgv(1)
bookmark_tag = '#' + Tools.getEnv('bookmark_tag')

search_terms = [bookmark_tag, query] if query else [bookmark_tag]

notes = Search()
matches = notes.url_search(search_terms)

alf = Items()
if matches:
    for m in matches:
        note_title = m['title']
        note_path = m['path']
        links = m['links']
        for l in links:
            url_title = l['url_title']
            url = l['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,
                        quicklookurl=url)
            alf.addMod('cmd',
                       note_path,
                       'Open MD Note',