Created
June 12, 2017 17:37
-
-
Save avalanchy/aadb4379b60f3e0cb72a328384553c1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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