Skip to content

Commit

Permalink
Merge pull request #2 from laymonage/0.3.1-info
Browse files Browse the repository at this point in the history
Rilis 0.3.1
  • Loading branch information
laymonage authored Apr 17, 2019
2 parents 1c6b663 + bf475d8 commit 75ac1a2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ pip install kbbi

Buat objek `KBBI` baru (contoh: `kata = KBBI('kata kunci')`), lalu manfaatkan
representasi `str`-nya dengan memanggil `str(kata)` atau ambil `dict` hasil
serialisasinya dengan memanggil `kata.serialisasi()`.
serialisasinya dengan memanggil `kata.serialisasi()`. Apabila ingin memanfaatkan
representasi `str`-nya tanpa contoh (jika ada), gunakan `__str__(contoh=False)`.

Untuk lebih jelasnya, lihat contoh berikut.

Expand Down
12 changes: 10 additions & 2 deletions kbbi/kbbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.. moduleauthor:: sage <[email protected]>
"""

from re import sub
from urllib.parse import quote

import requests
Expand Down Expand Up @@ -72,8 +73,11 @@ def serialisasi(self):
self.nama: [entri.serialisasi() for entri in self.entri]
}

def __str__(self):
return '\n\n'.join(str(entri) for entri in self.entri)
def __str__(self, contoh=True):
result = '\n\n'.join(str(entri) for entri in self.entri)
if not contoh:
result = sub(':.*', '', result)
return result

def __repr__(self):
return "<KBBI: {}>".format(self.nama)
Expand Down Expand Up @@ -241,6 +245,7 @@ def _init_kelas(self, makna_label):

kelas = makna_label.find(color='red')
lain = makna_label.find(color='darkgreen')
info = makna_label.find(color='green')
if kelas:
kelas = kelas.find_all('span')
if lain:
Expand All @@ -251,6 +256,7 @@ def _init_kelas(self, makna_label):
self.kelas = {
k.text.strip(): k['title'].strip() for k in kelas
} if kelas else {}
self.info = info.text.strip() if info else ''

def _init_contoh(self, makna_label):
"""Memproses contoh yang ada dalam makna.
Expand All @@ -276,6 +282,7 @@ def serialisasi(self):
return {
"kelas": self.kelas,
"submakna": self.submakna,
"info": self.info,
"contoh": self.contoh
}

Expand Down Expand Up @@ -306,6 +313,7 @@ def _contoh(self):
def __str__(self):
hasil = self._kelas() + ' ' if self.kelas else ''
hasil += self._submakna()
hasil += ' ' + self.info if self.info else ''
hasil += ': ' + self._contoh() if self.contoh else ''
return hasil

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='kbbi',
version='0.3.0',
version='0.3.1',
description=(
"A module that scraps a page in the online Indonesian dictionary (KBBI)"
),
Expand Down

0 comments on commit 75ac1a2

Please sign in to comment.