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

Rilis 0.3.1 #2

Merged
merged 3 commits into from
Apr 17, 2019
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
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