Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move etymology lookup to wiktionary #1178

Merged
merged 2 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 0 additions & 98 deletions sopel/modules/etymology.py

This file was deleted.

27 changes: 24 additions & 3 deletions sopel/modules/wiktionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def wikt(word):
etymology = None
definitions = {}
for line in bytes.splitlines():
if 'id="Etymology"' in line:
if 'id="Etymology"' in line or 'id="Etymology_1"' in line:
mode = 'etymology'
elif 'id="Noun"' in line:
mode = 'noun'
Expand All @@ -55,7 +55,7 @@ def wikt(word):
elif 'id="' in line:
mode = None

elif (mode == 'etmyology') and ('<p>' in line):
elif (mode == 'etymology') and ('<p>' in line):
etymology = text(line)
elif (mode is not None) and ('<li>' in line):
definitions.setdefault(mode, []).append(text(line))
Expand All @@ -80,7 +80,7 @@ def format(result, definitions, number=2):


@commands('wt', 'define', 'dict')
@example('.wt bailiwick')
@example('.wt bailiwick', "bailiwick — noun: 1. The district within which a bailie or bailiff has jurisdiction, 2. A person's concern or sphere of operations, their area of skill or authority")
def wiktionary(bot, trigger):
"""Look up a word on Wiktionary."""
word = trigger.group(2)
Expand All @@ -102,3 +102,24 @@ def wiktionary(bot, trigger):
if len(result) > 300:
result = result[:295] + '[...]'
bot.say(result)


@commands('ety')
@example('.ety bailiwick', "bailiwick: From bailie (“bailiff”) and wick (“dwelling”), from Old English wīc.")
def wiktionary_ety(bot, trigger):
"""Look up a word's etymology on Wiktionary."""
word = trigger.group(2)
if word is None:
bot.reply('You must give me a word!')
return

etymology, _definitions = wikt(word)
if not etymology:
bot.say("Couldn't get the etymology for %s." % word)
return

result = "{}: {}".format(word, etymology)

if len(result) > 300:
result = result[:295] + '[...]'
bot.say(result)