This commit is contained in:
Luke Tainton (ltainton)
2023-04-05 20:57:31 +01:00
parent be6546e4cc
commit 102b74e90a
21 changed files with 409 additions and 13 deletions

0
app/utils/__init__.py Normal file
View File

36
app/utils/config.py Normal file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env python3
import os
class Config:
def __init__(self) -> None:
self.__bot_name: str = os.environ["BOT_NAME"]
self.__webex_token: str = os.environ["WEBEX_API_KEY"]
self.__admin_first_name: str = os.environ["ADMIN_FIRST_NAME"]
self.__admin_emails: list = os.environ["ADMIN_EMAIL"].split(",")
self.__n8n_webhook_url: str = os.environ["N8N_WEBHOOK_URL"]
@property
def bot_name(self) -> str:
return self.__bot_name
@property
def webex_token(self) -> str:
return self.__webex_token
@property
def admin_first_name(self) -> str:
return self.__admin_first_name
@property
def admin_emails(self) -> list:
return self.__admin_emails
@property
def n8n_webhook_url(self) -> str:
return self.__n8n_webhook_url
config: Config = Config()

7
app/utils/datetime.py Normal file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env python3
from datetime import datetime
def timestamp_to_date(timestamp: int) -> str:
return datetime.utcfromtimestamp(timestamp).strftime("%Y-%m-%d")

26
app/utils/n8n.py Normal file
View File

@ -0,0 +1,26 @@
import requests
from app.utils.config import config
def __n8n_post(data: dict) -> bool:
headers: dict = {"Content-Type": "application/json"}
resp: requests.Response = requests.post(
url=config.n8n_webhook_url,
headers=headers,
json=data,
timeout=10,
verify=False,
)
return bool(resp.status_code == 200)
def submit_task(summary, description, completion_date, requestor) -> bool:
print(f"submit_task: {completion_date=}")
data: dict = {
"requestor": requestor,
"title": summary,
"description": description,
"completiondate": completion_date,
}
return __n8n_post(data=data)