From 149f02af90143374ed6151ec3bfedbb9096ef73d Mon Sep 17 00:00:00 2001 From: Paul Walko Date: Fri, 17 Feb 2017 19:52:26 +0000 Subject: [PATCH] Change etymology/definition syntax for parsing json --- modules/wiktionary.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/wiktionary.py b/modules/wiktionary.py index 8770d1d..f85a109 100644 --- a/modules/wiktionary.py +++ b/modules/wiktionary.py @@ -48,29 +48,31 @@ def wiktionary(word): etymology = None definitions = {} for line in result.splitlines(): - if line == '===Etymology===': + if 'Etymology' in line: mode = 'etymology' - elif 'Noun' in line: + elif '==Noun==' in line: mode = 'noun' - elif 'Verb' in line: + elif '==Verb==' in line: mode = 'verb' - elif 'Adjective' in line: + elif '==Adjective==' in line: mode = 'adjective' - elif 'Adverb' in line: + elif '==Adverb==' in line: mode = 'adverb' - elif 'Interjection' in line: + elif '==Interjection==' in line: mode = 'interjection' elif 'Particle' in line: mode = 'particle' - elif 'Preposition' in line: + elif '==Preposition==' in line: mode = 'preposition' - elif len(line) == 0: - mode = None +# elif len(line) == 0: +# mode = None elif mode == 'etymology': etymology = text(line) + mode = None elif mode is not None and '#' in line: definitions.setdefault(mode, []).append(text(line)) + mode = None if '====Synonyms====' in line: break