Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Merge 12deff8 into 787dea5
Browse files Browse the repository at this point in the history
  • Loading branch information
wdv4758h committed Aug 19, 2019
2 parents 787dea5 + 12deff8 commit f666ca7
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions zdict/dictionaries/urban.py
@@ -1,5 +1,7 @@
import json

from random import randint

from zdict.dictionary import DictBase
from zdict.exceptions import NotFoundError
from zdict.models import Record
Expand All @@ -23,25 +25,35 @@ def _get_url(self, word) -> str:
def show(self, record: Record):
content = json.loads(record.content)

data = content['list'][0]
# hybrid way to select showing answers
# first 3 answers + random 1 answer from rest of them
answers = content['list'][:3]
answers_length = len(content['list'])
if answers_length > 3:
answers.append(content['list'][randint(3, answers_length-1)])

# print word
self.color.print(data.get('word', ''), 'yellow')
for data in answers:
word = data.get('word', '')
if "</h1>" in word: # there are some wierd case, e.g. "asdasd"
continue

self.color.print(
data.get('definition', ''),
'org',
indent=2,
)
# print word
self.color.print(word, 'yellow')

for example in data.get('example', '').split('\n'):
self.color.print(
example,
'indigo',
data.get('definition', ''),
'org',
indent=2,
)

print()
for example in data.get('example', '').split('\n'):
self.color.print(
example,
'indigo',
indent=2,
)

print()

def query(self, word: str):
content_str = self._get_raw(word)
Expand Down

0 comments on commit f666ca7

Please sign in to comment.