Change etymology/definition syntax for parsing json
parent
f02bcae388
commit
149f02af90
|
@ -48,29 +48,31 @@ def wiktionary(word):
|
||||||
etymology = None
|
etymology = None
|
||||||
definitions = {}
|
definitions = {}
|
||||||
for line in result.splitlines():
|
for line in result.splitlines():
|
||||||
if line == '===Etymology===':
|
if 'Etymology' in line:
|
||||||
mode = 'etymology'
|
mode = 'etymology'
|
||||||
elif 'Noun' in line:
|
elif '==Noun==' in line:
|
||||||
mode = 'noun'
|
mode = 'noun'
|
||||||
elif 'Verb' in line:
|
elif '==Verb==' in line:
|
||||||
mode = 'verb'
|
mode = 'verb'
|
||||||
elif 'Adjective' in line:
|
elif '==Adjective==' in line:
|
||||||
mode = 'adjective'
|
mode = 'adjective'
|
||||||
elif 'Adverb' in line:
|
elif '==Adverb==' in line:
|
||||||
mode = 'adverb'
|
mode = 'adverb'
|
||||||
elif 'Interjection' in line:
|
elif '==Interjection==' in line:
|
||||||
mode = 'interjection'
|
mode = 'interjection'
|
||||||
elif 'Particle' in line:
|
elif 'Particle' in line:
|
||||||
mode = 'particle'
|
mode = 'particle'
|
||||||
elif 'Preposition' in line:
|
elif '==Preposition==' in line:
|
||||||
mode = 'preposition'
|
mode = 'preposition'
|
||||||
elif len(line) == 0:
|
# elif len(line) == 0:
|
||||||
mode = None
|
# mode = None
|
||||||
|
|
||||||
elif mode == 'etymology':
|
elif mode == 'etymology':
|
||||||
etymology = text(line)
|
etymology = text(line)
|
||||||
|
mode = None
|
||||||
elif mode is not None and '#' in line:
|
elif mode is not None and '#' in line:
|
||||||
definitions.setdefault(mode, []).append(text(line))
|
definitions.setdefault(mode, []).append(text(line))
|
||||||
|
mode = None
|
||||||
|
|
||||||
if '====Synonyms====' in line:
|
if '====Synonyms====' in line:
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue