fastapi-basic 0.1.0__py3-none-any.whl → 0.1.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of fastapi-basic might be problematic. Click here for more details.
- fastapi_basic/database/__init__.py +0 -0
- fastapi_basic/database/mongodb.py +29 -0
- fastapi_basic/exception/base_exception.py +10 -0
- fastapi_basic/ext/line/__init__.py +29 -0
- {fastapi_basic-0.1.0.dist-info → fastapi_basic-0.1.2.dist-info}/METADATA +1 -1
- {fastapi_basic-0.1.0.dist-info → fastapi_basic-0.1.2.dist-info}/RECORD +8 -5
- {fastapi_basic-0.1.0.dist-info → fastapi_basic-0.1.2.dist-info}/WHEEL +0 -0
- {fastapi_basic-0.1.0.dist-info → fastapi_basic-0.1.2.dist-info}/top_level.txt +0 -0
|
File without changes
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from beanie import init_beanie
|
|
2
|
+
from motor.motor_asyncio import AsyncIOMotorClient
|
|
3
|
+
|
|
4
|
+
class MongoDB:
|
|
5
|
+
def __init__(self, username: str, password: str, host: str, port: int, db_name: str, ssl: str=None, ssl_ca_certs: str=None):
|
|
6
|
+
self.username = username
|
|
7
|
+
self.password = password
|
|
8
|
+
self.host = host
|
|
9
|
+
self.port = port
|
|
10
|
+
self.db_name = db_name
|
|
11
|
+
self.ssl = ssl
|
|
12
|
+
self.ssl_ca_certs = ssl_ca_certs
|
|
13
|
+
|
|
14
|
+
async def connect(self, document_models: list):
|
|
15
|
+
db_settings = dict(
|
|
16
|
+
username=self.username,
|
|
17
|
+
password=self.password,
|
|
18
|
+
host=self.host,
|
|
19
|
+
port=self.port,
|
|
20
|
+
retryWrites=False
|
|
21
|
+
)
|
|
22
|
+
if self.ssl:
|
|
23
|
+
db_settings["ssl"] = self.ssl
|
|
24
|
+
|
|
25
|
+
if self.ssl_ca_certs and self.ssl_ca_certs != "":
|
|
26
|
+
db_settings["tlsCAFile"] = self.ssl_ca_certs
|
|
27
|
+
|
|
28
|
+
self.client = AsyncIOMotorClient(**db_settings)
|
|
29
|
+
await init_beanie(database=self.client[self.db_name], document_models=document_models)
|
|
@@ -11,3 +11,13 @@ class InternalBaseException(HTTPException):
|
|
|
11
11
|
"data": kwargs,
|
|
12
12
|
}
|
|
13
13
|
super().__init__(status_code=status_code, detail=detail)
|
|
14
|
+
|
|
15
|
+
class LineBotException(HTTPException):
|
|
16
|
+
def __init__(self, status_code: int = status.HTTP_502_BAD_GATEWAY, code: str = "line_bot_error",
|
|
17
|
+
message: str = "Line bot error", **kwargs):
|
|
18
|
+
detail = {
|
|
19
|
+
"code": code,
|
|
20
|
+
"message": message,
|
|
21
|
+
"data": kwargs,
|
|
22
|
+
}
|
|
23
|
+
super().__init__(status_code=status_code, detail=detail)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from linebot import LineBotApi, WebhookHandler
|
|
2
|
+
from linebot.exceptions import LineBotApiError
|
|
3
|
+
from linebot.models import TextMessage, TextSendMessage
|
|
4
|
+
|
|
5
|
+
from ...exception.base_exception import LineBotException
|
|
6
|
+
|
|
7
|
+
class LineBot:
|
|
8
|
+
def __init__(self, channel_access_token: str, channel_secret: str):
|
|
9
|
+
self.channel_access_token = channel_access_token
|
|
10
|
+
self.channel_secret = channel_secret
|
|
11
|
+
self.line_bot_api = LineBotApi(self.channel_access_token)
|
|
12
|
+
self.handler = WebhookHandler(self.channel_secret)
|
|
13
|
+
|
|
14
|
+
async def reply_message(self, event, message):
|
|
15
|
+
try:
|
|
16
|
+
self.line_bot_api.reply_message(event.reply_token, TextMessage(text=message))
|
|
17
|
+
|
|
18
|
+
except LineBotApiError as err:
|
|
19
|
+
exception = LineBotException(str(err))
|
|
20
|
+
raise exception
|
|
21
|
+
|
|
22
|
+
async def push_message(self, line_uid: str, text: str):
|
|
23
|
+
try:
|
|
24
|
+
self.line_bot_api.push_message(line_uid, TextSendMessage(text=text))
|
|
25
|
+
|
|
26
|
+
except LineBotApiError as err:
|
|
27
|
+
message = f"Send line message fail, line_uid: {line_uid}, text: {text}, err: {str(err)}"
|
|
28
|
+
exception = LineBotException(message)
|
|
29
|
+
raise exception
|
|
@@ -3,12 +3,15 @@ fastapi_basic/base_config.py,sha256=nimiiK5LRY9kmx3dBDbN7teO4R8E423-c2iyq9WMcCg,
|
|
|
3
3
|
fastapi_basic/base_factory.py,sha256=xrM4tbKjrhtqpzP2hupGJxiNeGsDnXfMYe8urOcq-ss,3801
|
|
4
4
|
fastapi_basic/const.py,sha256=UA7-Eefu_dbWpbFn09Ei_BPb903SExnCgVbnm8_3ALE,99
|
|
5
5
|
fastapi_basic/utils.py,sha256=8ympyQIXsKkxLILTI_7ug85vmKWYKqX0mpADjgHekgU,306
|
|
6
|
+
fastapi_basic/database/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
fastapi_basic/database/mongodb.py,sha256=XW7ApqYkR1Jf7LM1HaZ6jzYgajzuu1whKw5cpsjSO-M,1017
|
|
6
8
|
fastapi_basic/exception/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
fastapi_basic/exception/base_exception.py,sha256=
|
|
9
|
+
fastapi_basic/exception/base_exception.py,sha256=VwMqn85rBeJCF6RIOYUR1eLxbP2aSDhhtAyyhYmBI84,855
|
|
8
10
|
fastapi_basic/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
11
|
fastapi_basic/ext/aws/__init__.py,sha256=N_cwnbv1N-F1SY6NenBOTZe20zGaKFu3UXAu17hFAXY,816
|
|
10
12
|
fastapi_basic/ext/aws/const.py,sha256=Mmb6lo11aZZDAVy-nK-v_JxtVPPKYUo9GB4ihH7XYuM,68
|
|
11
|
-
fastapi_basic
|
|
12
|
-
fastapi_basic-0.1.
|
|
13
|
-
fastapi_basic-0.1.
|
|
14
|
-
fastapi_basic-0.1.
|
|
13
|
+
fastapi_basic/ext/line/__init__.py,sha256=ZyCTuvW9P_iaMr2lFXp0JEEQMK773qOTnWiUdxIwAS8,1170
|
|
14
|
+
fastapi_basic-0.1.2.dist-info/METADATA,sha256=AVeideHs4DOieR-m9ec0KSbnJ_2sFxG_X6btu8PCbyw,1740
|
|
15
|
+
fastapi_basic-0.1.2.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
16
|
+
fastapi_basic-0.1.2.dist-info/top_level.txt,sha256=Q9PdwWxaB4dy135MQHiroRYOqArdUSaIeEkzYinN6W0,14
|
|
17
|
+
fastapi_basic-0.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|