Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dyohan9 committed Jan 16, 2020
1 parent ebe8136 commit 26c6b38
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 119
ignore = E501,W503,E203
14 changes: 14 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
"flake8" = "*"
black = "==19.10b0"

[packages]
requests = "==2.22.0"

[requires]
python_version = "3.6"
189 changes: 189 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bothub/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .bothub import Bothub # noqa: F401
39 changes: 39 additions & 0 deletions bothub/bothub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import requests


class BothubError(Exception):
pass


class Bothub(object):
authorization = None

def __init__(self, authorization):
self.authorization = authorization

@staticmethod
def _request(authorization, method, path, data, **kwargs):
request = requests.request(
method=method,
url=f"https://nlp.bothub.it/{path}",
headers={"Authorization": f"Bearer {authorization}"},
json=data,
**kwargs,
)
if request.status_code > 200:
raise BothubError(
f"Bothub status_code: {request.status_code} ({request.reason})"
)
json = request.json()

return json

def parse(self, text, language=None, rasa_format=False):
data = {"text": text}
if language:
data["language"] = language
if rasa_format:
data["rasa_format"] = rasa_format

result = self._request(self.authorization, "POST", "v2/parse", data)
return result
4 changes: 4 additions & 0 deletions examples/parse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from bothub import Bothub

client = Bothub(authorization="<AUTHORIZATION>")
print(client.parse(text="okay"))
12 changes: 12 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from setuptools import setup, find_packages


setup(
name='bothub',
version='1.0.0',
packages=find_packages(),
install_requires=[
'requests >= 2.0.0, <= 2.22.0',
],
python_requires='>=3.4',
)

0 comments on commit 26c6b38

Please sign in to comment.