Esempio n. 1
0
def main(wf):
    """Run Script Filter."""
    global thumbs
    # Initialise thumbnail generator
    thumbs = Thumbs(wf.cachefile('thumbs'))

    query = None
    if len(wf.args):
        query = wf.args[0].strip()

    gifs = load_gifs()

    if query:
        gifs = wf.filter(query, gifs, key=attrgetter('name'), min_score=30)

    if not gifs:
        wf.add_item('No matching GIFs',
                    'Try a different query',
                    icon=ICON_WARNING)
        wf.send_feedback()
        return

    # Display results
    for gif in gifs:
        it = wf.add_item(gif.name,
                         'Copy URL to clipboard',
                         arg=gif.url,
                         quicklookurl=gif.url,
                         icon=gif.icon,
                         valid=True)

        # Alternate actions
        mod = it.add_modifier('cmd', 'Open in Browser', arg=gif.url)
        mod.setvar('action', 'browse')

        mod = it.add_modifier('alt', 'Copy as BB Code', arg=bb_image(gif.url))
        mod.setvar('action', 'bbcode')

        mod = it.add_modifier('ctrl',
                              'Copy as Markdown',
                              arg=markdown_image(gif.url))
        mod.setvar('action', 'markdown')

    wf.send_feedback()

    # Generate thumbnails if necessary
    thumbs.save_queue()
    if thumbs.has_queue and not is_running('generate_thumbnails'):
        run_in_background(
            'generate_thumbnails',
            ['/usr/bin/python',
             wf.workflowfile('thumbnails.py')])

    return 0
Esempio n. 2
0
def main(wf):
    if len(wf.args):
        query = wf.args[0]
    else:
        query = None

    log.debug("query : %r", query)

    results = search_analogue(query=query)

    log.debug("%d results.", len(results))

    if not results:
        wf.add_item(
            'No results found for "%s".' % query,
            "Try a different query or add a link.",
            icon=ICON_FILES,
        )

    thumbs = Thumbs(wf.datafile("thumbs"))

    for hit in results:
        wf.add_item(
            title=hit["title"],
            subtitle=hit["excerpt"],
            valid=True,
            arg="https://analogue.app/{}/{}/".format(hit["form_slug"],
                                                     hit["slug"]),
            icon=thumbs.thumbnail(hit.get("image_url")),
            icontype=None,
        )

    wf.send_feedback()

    thumbs.save_queue()
    if thumbs.has_queue:
        thumbs.process_queue()
        # TODO run in background
        # if not is_running('generate_thumbnails'):
        #     run_in_background('generate_thumbnails',
        #                       ['/usr/bin/python',
        #                        wf.workflowfile('thumbnails.py')])

    return 0
Esempio n. 3
0
def main(wf):
    if wf.args:
        query = wf.args[0]
    else:
        query = None

    log.debug("query : %r", query)

    results = search_analogue(query=query)

    log.debug("%d results.", len(results))

    if not results:
        wf.add_item(
            'No results found for "%s".' % query,
            "Try a different query or add a link.",
            icon=ICON_FILES,
        )

    thumbs = Thumbs(wf.datafile("thumbs"))

    for hit in results:
        wf.add_item(
            title=hit["title"],
            subtitle=hit["excerpt"],
            valid=True,
            arg="https://analogue.app/{}/{}/".format(hit["form_slug"],
                                                     hit["slug"]),
            icon=thumbs.thumbnail(hit.get("image_url")),
            icontype=None,
        )

    wf.send_feedback()

    thumbs.save_queue()
    if thumbs.has_queue:
        thumbs.process_queue()

    return 0
Esempio n. 4
0
def thumbs():
    global _thumbs
    if _thumbs is None:
        _thumbs = Thumbs(wf.datafile('thumbs'))
    return _thumbs
Esempio n. 5
0
def thumbs():
    """Return global `Thumbs` object, creating first if necessary."""
    global _thumbs
    if _thumbs is None:
        _thumbs = Thumbs(wf.datafile('thumbs'))
    return _thumbs