Jump to content

It's a Python code question for the workflow


Recommended Posts

I'd like to know how to modify the code in order to place the currently entered search word at the bottom of the autocomplete list.

Thank you in advance! 🙏

 

36292496_2021-12-246_03_06.png.bae419a798cfa2ef618e2f2bc53412ab.png

 

 

import sys
from workflow import web, Workflow

def get_dictionary_data(word):
    url = 'https://ac-dict.naver.com/koko/ac'
    params = dict(frm='stdkrdic', oe='utf8', m=0, r=1, st=111, r_lt=111, q=word)
    r = web.get(url, params)
    r.raise_for_status()
    return r.json()

def main(wf):
    import cgi;
    args = wf.args[0]
    wf.add_item(title = 'Search Naver Krdic for \'%s\'' % args,
                autocomplete=args,
                arg=args,
                valid=True)
    def wrapper():
        return get_dictionary_data(args)
    res_json = wf.cached_data("kr_%s" % args, wrapper, max_age=600)
    for items in res_json['items']:
        for ltxt in items:
            if len(ltxt) > 0:
                txt = ltxt[0][0]
                wf.add_item(title = u"%s" % txt ,
                            subtitle = 'Search Naver Krdic for \'%s\'' % txt,
                            autocomplete=txt,
                            arg=txt,
                            valid=True);
    wf.send_feedback()
if __name__ == '__main__':
    wf = Workflow()
    sys.exit(wf.run(main))

 

Edited by greedist
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...