-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from laymonage/0.3.1-info
Rilis 0.3.1
- Loading branch information
Showing
3 changed files
with
13 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
.. moduleauthor:: sage <[email protected]> | ||
""" | ||
|
||
from re import sub | ||
from urllib.parse import quote | ||
|
||
import requests | ||
|
@@ -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) | ||
|
@@ -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: | ||
|
@@ -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. | ||
|
@@ -276,6 +282,7 @@ def serialisasi(self): | |
return { | ||
"kelas": self.kelas, | ||
"submakna": self.submakna, | ||
"info": self.info, | ||
"contoh": self.contoh | ||
} | ||
|
||
|
@@ -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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters