Skip to content

Instantly share code, notes, and snippets.

@ddksr ddksr/
Created Feb 1, 2015

What would you like to do?
DIS script
#!/usr/bin/env python3
"""DIS slovarček api
dis [options] [QUERY [QUERY ...]]
-h --help Show this screen.
--version Show version.
from urllib.request import urlopen
from urllib.parse import urlencode
from pyquery import PyQuery as pq
from docopt import docopt
LINE_QUERY = '{}:\n'
LINE_RESULT = ' * {} -> {}\n'
def search(query):
print(LINE_QUERY.format(query), end='')
results = pq(url=SEARCH_URL.format(urlencode({ 'text': query })),
opener=lambda url, **kw: urlopen(url).read().decode('utf8'))
for acc in results('div#all-search-results div.accordion'):
acc = pq(acc)
left = acc(' p').text()
right = acc(' p').text()
print(LINE_RESULT.format(left, right), end='')
if __name__ == '__main__':
arguments = docopt(__doc__, version='0.1')
queries = arguments.get('QUERY')
if queries:
search(' '.join(queries))
import subprocess
p = subprocess.Popen(['xclip', '-o'], stdout=subprocess.PIPE)
out, err = p.communicate()
if not err:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.