Skip to content

Instantly share code, notes, and snippets.

@avalanchy
Created June 12, 2017 17:37
Show Gist options
  • Save avalanchy/aadb4379b60f3e0cb72a328384553c1d to your computer and use it in GitHub Desktop.
Save avalanchy/aadb4379b60f3e0cb72a328384553c1d to your computer and use it in GitHub Desktop.
import sys
import pyquery
import requests
SYNONIMY_URL = 'https://www.synonimy.pl/synonim/{}/'
WORDS_PER_LINE = 5
if len(sys.argv) < 2:
print('Podaj słowo')
exit()
searched_word = sys.argv[1]
url = SYNONIMY_URL.format(searched_word)
response = requests.get(url)
pq = pyquery.PyQuery(response.text)
elements = pq('a.load_word')
found_words = (x.text for x in elements)
words_count = len(elements)
output = ''
for i, word in enumerate(found_words, start=1):
if i == words_count:
append = '.\n'
elif i % WORDS_PER_LINE == 0:
append = ',\n'
else:
append = ', '
output += word + append
print(output)
i=__import__;exit(' '.join(x.text for x in i('pyquery').PyQuery(url='https://www.synonimy.pl/synonim/%s/'%i('sys').argv[1])('.load_word')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment