Skip to content

Commit

Permalink
Tambahkan antarmuka CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
prasastoadi committed Oct 31, 2019
1 parent 1a52ba8 commit 12b1488
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ pip install kbbi

### Manual

1. Lakukan instalasi untuk paket-paket prasyarat ([`requests`][requests]
dan [`BeautifulSoup4`][beautifulsoup4]).
1. Lakukan instalasi untuk paket-paket prasyarat ([`requests`][requests], [`BeautifulSoup4`][beautifulsoup4], dan [`Abseil`][abseil]).
2. Klonakan repositori ini atau unduh [`kbbi.py`][kbbi-py].
3. Letakkan `kbbi.py` dalam direktori yang Anda inginkan.

Expand Down Expand Up @@ -113,6 +112,22 @@ tak.sir [2]
}
```

Penggunaan melalui CLI.
```
$ python kbbi.py --kata=cinta
```

Pencarian frasa yang dipisahkan oleh spasi harus diapit oleh tanda petik.
```
$ python kbbi.py --kata="tanggung jawab"
```

Menambahkan contoh kalimat.
```
$ python kbbi.py --kata="tanggung jawab" --contoh
```


## Lisensi

Proyek ini didistribusikan dengan lisensi [MIT][license].
Expand All @@ -131,7 +146,8 @@ penyalahgunaan yang mungkin muncul dari proyek ini.
[kbbi]: https://kbbi.kemdikbud.go.id
[requests]: https://pypi.org/project/requests
[beautifulsoup4]: https://pypi.org/project/requests/beautifulsoup4
[kbbi-py]: kbbi/kbbi.py
[abseil]: https://github.com/abseil/abseil-py
[kbbi-py]: kbbi/kbbi.py
[license]: LICENSE
[hukum]: https://kbbi.kemdikbud.go.id/Beranda/Hukum
[badan-bahasa]: http://badanbahasa.kemdikbud.go.id
Expand Down
24 changes: 24 additions & 0 deletions kbbi/kbbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
import requests
from bs4 import BeautifulSoup

from absl import app
from absl import flags


FLAGS = flags.FLAGS

flags.DEFINE_string("kata", None, "Kata yang dicari.")
flags.DEFINE_boolean("contoh", False, 'Menampilkan contoh kalimat.')

flags.mark_flag_as_required('kata')

class KBBI:
"""Sebuah laman dalam KBBI daring."""
Expand Down Expand Up @@ -330,3 +340,17 @@ def ambil_teks_dalam_label(sup):
:rtype: str
"""
return ''.join(i.strip() for i in sup.find_all(text=True, recursive=False))


def main(argv):

kata = KBBI(FLAGS.kata)
contoh = False
if FLAGS.contoh:
contoh = True

print(kata.__str__(contoh=contoh))


if __name__ == '__main__':
app.run(main)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
install_requires=[
'requests',
'beautifulsoup4',
'absl-py',
],
)

0 comments on commit 12b1488

Please sign in to comment.